LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   WxPython: sizers, panels, frames confusion (https://www.linuxquestions.org/questions/programming-9/wxpython-sizers-panels-frames-confusion-696723/)

browny_amiga 01-12-2009 08:13 AM

WxPython: sizers, panels, frames confusion
 
Hi

I am pretty new to WxPython, have been playing around with sizers and panels and so far could not grasp how they relate to eachother.

You first create a frame, which is the container for the others, but how do panels relate to sizers? Can widgets (like buttons be contained by panels and sizers?)
Unfortunately, there is no simple straight forwards explaination what a panel is, what it is good for and for what not.
Also, where do you define the size of sizer-cells?

From my questions, you might figure that I don't understand "how it all fits together".

Cheers

Markus

browny_amiga 01-13-2009 09:58 AM

It is a shame that nobody seems to know. I dug a little more, but still can't figure out how panels relate to sizers and vice versa.

I guess I should write a comprehensive noob tutorial once I have figured it out, since many newbies must get shipwrecked on the highly complicated widgets of WxPython.

One thing that also baffles me is why a normal window is called a frame. Yet, there are windows, which seems to be everything and nothing at the same time.

Markus

jcookeman 01-13-2009 01:50 PM

If you think wxPython is "complicated" you should see other windowing toolkits:

Code:

class UserDiag(wx.Dialog):
    def __init__(self):
        wx.Dialog.__init__(self, None, -1, 'Login',
                          size=(300, 100))
        panel = wx.Panel(self, -1)
        usrLabel = wx.StaticText(panel, -1, "Username:")
        self.usrText = wx.TextCtrl(panel, -1, size=(175, -1))
        pwdLabel = wx.StaticText(panel, -1, "Password:")
        self.pwdText = wx.TextCtrl(panel, -1, size=(175, -1),
                                  style=wx.TE_PASSWORD)
        okButton = wx.Button(panel, label="OK")
        cancelButton = wx.Button(panel, label="Close")
        sizer = wx.FlexGridSizer(cols=2, hgap=6, vgap=6)
        sizer.AddMany([usrLabel, self.usrText, pwdLabel, self.pwdText,
                      okButton, cancelButton])
        panel.SetSizer(sizer)
        self.Bind(wx.EVT_BUTTON, self.onOK, okButton)
        self.Bind(wx.EVT_BUTTON, self.onClose, cancelButton)
        self.Bind(wx.EVT_CLOSE, self.onCloseWindow)
    def onOK(self, event):
        self.Close(True)
    def onClose(self, event):
        self.Close(True)
    def onCloseWindow(self, event):
        self.Destroy()

It's not a well-refined example, but it shows how simple sizers are. Frame is analogous with a window frame and the rest of the contents that are contained inside. Generally, Frames contain panels which contain sizers which further contain other widgets. And, yes, these can contain other nested sizers if wished. Most simple GUIs don't require this.

browny_amiga 01-22-2009 04:09 AM

[solved]
 
Thanks, that helps me already big deal.

Markus


All times are GMT -5. The time now is 06:59 PM.