[wxPython] Stuck with wxBoxSizer

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

[wxPython] Stuck with wxBoxSizer

Norbert.Klamann


Hello all,
I try to build an interface for a python app and can't figure out how to make
the
wxBoxSizer work.
The following simplified sample shows the problem. I want to place 2 Buttons and
see just 1.

I think I miss something obvious, but at the moment I am stuck. Many thanks for
any help.

The  wxPython - Demo is very impressive, BTW. Many thanks for it, Robin Dunn.
<-------------------------------------------------------sample begins
from wxPython.wx import *
class MyFrame(wxFrame):
    def __init__(self, parent):
        wxFrame.__init__(self, parent,-1, "Projektverwaltung")
        panel = wxPanel(self, -1)
        innerbox = wxBoxSizer(wxVERTICAL)
        innerbox.Add(  wxButton(self, 10, "A"), 0, wxEXPAND)
        innerbox.Add(  wxButton(self, 101, "B"), 1, wxEXPAND)
        self.SetSizer (innerbox)
        EVT_SIZE(self, self.OnSize)

    def OnSize(self,event):
        self.sizer.Layout(self.GetClientSize())
    def OnCloseWindow(self, event):
        self.Destroy()
class MyApp(wxApp):
    def OnInit(self):
        frame = MyFrame(NULL)
        frame.Show(true)
        self.SetTopWindow(frame)
        return true
def main():
    app = MyApp(0)     # Create an instance of the application class
    app.MainLoop()     # Tell it to start processing events
main()
<-------------------------------------------------------sample ends





Norbert Klamann
--------------------------------------+---------------------------------
Norbert Klamann                       | Mittelstr.2
Klamann Software & Beratung GmbH      | D-50374 Erftstadt
Tel.: +49 2235 985272                 | Germany
Fax : +49 2235 985273                 |
email: [hidden email]     |
--------------------------------------+---------------------------------



_______________________________________________
wxPython-users maillist  -  [hidden email]
http://starship.python.net/mailman/listinfo/wxpython-users



Reply | Threaded
Open this post in threaded view
|

Re: [wxPython] Stuck with wxBoxSizer

Robin Dunn
>
> I think I miss something obvious, but at the moment I am stuck. Many thanks
for
> any help.
>

You should run from a console window so you see the tracebacks:

Traceback (innermost last):
  File "E:\temp\Others\sizer.py", line 13, in OnSize
    self.sizer.Layout(self.GetClientSize())
AttributeError: sizer

You are not saving a reference to the innerbox in self.sizer.  In fact, you
don't need to.  The following is suffient:

    def OnSize(self,event):
        self.Layout()

Even this is unnecessary.  The wxFrame supports auto-layout.  If you add the
following to the __init__ method then you don't have to handle the EVT_SIZE
event at all.

        self.SetAutoLayout(true)

--
Robin Dunn
Software Craftsman
[hidden email]
http://AllDunn.com/robin/
http://AllDunn.com/wxPython/  Check it out!




_______________________________________________
wxPython-users maillist  -  [hidden email]
http://starship.python.net/mailman/listinfo/wxpython-users