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

独自空忆成欢 提交于 2019-12-11 13:16:42

问题


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()```

回答1:


Just add the size when creating the Frame:

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


来源:https://stackoverflow.com/questions/19576850/how-do-i-make-a-gui-open-with-the-correct-size-with-wxpython

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!