Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7853625
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T19:45:10+00:00 2026-06-02T19:45:10+00:00

I’m teaching myself (Wx) Python and got stuck. I want to create a child

  • 0

I’m teaching myself (Wx) Python and got stuck. I want to create a child window that has a recurring set of information inside of my TestFrame, which contains most of my code. The problem is, it only shows one widget in my code. I am trying to figure out the following, in order of importance to me.

**Note that this code is an extension to this page.*

  1. How can I allow multiple widgets in the “AddBox” class to appear correctly?
  2. When my window is resized, it corrupts the button images as in the screen attached. How could I fix this?
  3. How do you call/bind each of these dynamically created widgets?
  4. Bonus: is the “OnSize” module needed here?

Thank you for your help. If allowed/appropriate, I’m willing to contribute $5 via Paypal to the winner if you PM me.

import wx

class AddBox(wx.Window):
    def __init__(self, parent):
        wx.Window.__init__(self, parent)        

        pbox = wx.BoxSizer(wx.VERTICAL)

        controlback = wx.Button(self, label="Back")
        controlforward = wx.Button(self, label="Forward")

        pbox.AddMany([(controlback, 1, wx.ALL), (controlforward, 1, wx.ALL)])

class TestFrame(wx.Frame):
    def __init__(self):
        wx.Frame.__init__(self, None, -1, size=(1000, 550))

        self.Bind(wx.EVT_SIZE, self.OnSize)

        pbox0 = wx.BoxSizer(wx.VERTICAL)
        controlback0 = wx.Button(self, label="Back0")
        controlforward0 = wx.Button(self, label="Forward0")
        pbox0.AddMany([(controlback0, 1, wx.ALL), (controlforward0, 1, wx.ALL)])
        pbox2 = wx.BoxSizer(wx.VERTICAL)

        self.scrolling_window = wx.ScrolledWindow( self )
        self.scrolling_window.SetScrollRate(1,6)
        self.scrolling_window.EnableScrolling(True,True)
        self.sizer_container = wx.BoxSizer( wx.VERTICAL )
        self.sizer = wx.BoxSizer( wx.VERTICAL )
        self.sizer_container.Add(self.sizer,1,wx.CENTER,wx.EXPAND)
        self.child_windows = []
        for i in range(0,8):
            wind = AddBox(self.scrolling_window)
            self.sizer.Add(wind, 0, wx.CENTER|wx.ALL, 5)
            self.child_windows.append(wind)

        self.scrolling_window.SetSizer(self.sizer_container)
        #self.Layout() #not needed?


        pbox2.AddMany([(self.sizer_container, 1, wx.ALL)])

    def OnSize(self, event):
        self.scrolling_window.SetSize(self.GetClientSize())

if __name__=='__main__':
    app = wx.PySimpleApp()
    f = TestFrame()
    f.Show()
    app.MainLoop()
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T19:45:12+00:00Added an answer on June 2, 2026 at 7:45 pm

    The code here is pretty convoluted and hard to follow. You almost never need to use wx.Window. In fact, in almost 6 years of using wxPython, I have NEVER used it directly. PySimpleApp is deprecated as well. Anyway, I cleaned up the code a bunch and re-did it below. I’m not sure if this is what you’re looking for or not though. Also note that I swapped out ScrolledWindow for ScrolledPanel as I think the latter is easier to use:

    import wx
    import  wx.lib.scrolledpanel as scrolled
    
    class TestFrame(wx.Frame):
        def __init__(self):
            wx.Frame.__init__(self, None, size=(1000, 550))
            panel = wx.Panel(self)
    
            mainSizer = wx.BoxSizer(wx.VERTICAL)
            pbox0 = wx.BoxSizer(wx.VERTICAL)
            controlback0 = wx.Button(panel, label="Back0")
            controlforward0 = wx.Button(panel, label="Forward0")
            pbox0.Add(controlback0, 0, wx.ALL)
            pbox0.Add(controlforward0, 0, wx.ALL)
            mainSizer.Add(pbox0)
    
            self.scrolling_window = scrolled.ScrolledPanel( panel )
            self.scrolling_window.SetAutoLayout(1)
            self.scrolling_window.SetupScrolling()
            self.sizer = wx.BoxSizer( wx.VERTICAL )
            self.child_windows = []
            for i in range(0,8):
                wind = self.addBox()
                self.sizer.Add(wind, 0, wx.CENTER|wx.ALL, 5)
            self.scrolling_window.SetSizer(self.sizer)
    
            mainSizer.Add(self.scrolling_window, 1, wx.EXPAND)
            panel.SetSizer(mainSizer)
    
        def addBox(self):
            pbox = wx.BoxSizer(wx.VERTICAL)
    
            controlback = wx.Button(self.scrolling_window, label="Back")
            controlforward = wx.Button(self.scrolling_window, label="Forward")
    
            pbox.AddMany([(controlback, 0, wx.ALL), (controlforward, 0, wx.ALL)])
            return pbox
    
        def OnSize(self, event):
            self.scrolling_window.SetSize(self.GetClientSize())
    
    if __name__=='__main__':
        app = wx.App(False)
        f = TestFrame()
        f.Show()
        app.MainLoop()
    

    You should also take a look at the Widget Inspection Tool. It will help you figure out layout problems like this: http://wiki.wxpython.org/Widget%20Inspection%20Tool

    EDIT: I think the code above takes care of items #1 and 2. For #3, see the following article I wrote last year: http://www.blog.pythonlibrary.org/2011/09/20/wxpython-binding-multiple-widgets-to-the-same-handler/

    Basically you bind in the loop itself and then in the event handler, you can use event.GetEventObject() to return the calling widget and set its value or whatever. As for your 4th question, I would say no, you don’t need the OnSize method. You almost never need to override that in wxPython and I certainly didn’t in my example code.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got a string that has curly quotes in it. I'd like to replace
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
Basically, what I'm trying to create is a page of div tags, each has
I have a French site that I want to parse, but am running into
I'm trying to create an if statement in PHP that prevents a single post
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I want use html5's new tag to play a wav file (currently only supported

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.