wnnmaw
wnnmaw

Reputation: 5534

How Do I Make a GUI Open with the Correct Size with wxPython?

I'm having trouble with the sizing of my window. When first opening the GUI, the initial size only shows a portion of what's in the window; its too small. Scroll bars are present so I can get to the information, but I want it to open with the correct size, rather than having to drag it diagonally so that all the information will be visible. Also, when expanding the window size, the appearance of the buttons glitches and the wording gets all choppy-like.

How can I change the sizers/scrolling so that the initial window will open to the correct size and all data will be shown?

Part of my code is listed below (a lot of information removed for simplicity), I know the form is bad, sorry. Thanks for the help!

class Part_1(wx.Frame):
    def __init__(self):
        wx.Frame.__init__(self, None, -1, 'CR Part 1')
        global panel

        panel = ScrolledPanel(self)         

        # LAYOUT -----------------------------------------------------
        # Setting up different sizers
        vbox = wx.BoxSizer(wx.VERTICAL)
        vbox.Add(lbl, flag=wx.ALIGN_CENTER|wx.ALIGN_CENTER_VERTICAL, border=10)

        staticbox = wx.StaticBoxSizer(wx.StaticBox(panel, wx.ID_ANY, u"Part 1: Initiation (completed by initiator)"), wx.VERTICAL)

        hbox1 = wx.BoxSizer(wx.HORIZONTAL)
        hbox1.Add((20,20), 1)
        hbox1.Add(crnum)
        hbox1.Add((0,0), 1)
        hbox1.Add(crrev)
        hbox1.Add((20,20), 1)


        hbox2 = wx.BoxSizer(wx.HORIZONTAL)
        hbox2.Add((20,20), 1)
        hbox2.Add(attachBtn)  
        hbox2.Add((20,20), 1)   

        staticbox.Add(hbox2, flag=wx.EXPAND|wx.LEFT|wx.RIGHT|wx.TOP|wx.BOTTOM, border=25)

        # Add sizers to the the main panel sizer
        vbox.Add(hbox1, flag=wx.EXPAND|wx.LEFT|wx.RIGHT|wx.TOP, border=10) 
        vbox.Add(staticbox, flag=wx.EXPAND|wx.LEFT|wx.RIGHT|wx.TOP, border=10) 
        panel.SetSizer(vbox)
        panel.SetupScrolling()```

Upvotes: 1

Views: 489

Answers (1)

user2859193
user2859193

Reputation: 434

Just add the size when creating the Frame:

wx.Frame.__init__(self, None, -1, 'CR Part 1', size=(800, 600))

Upvotes: 1

Related Questions