"Tkinter"-like layout with sizers and frames?

Howdy y'all,

I am trying to emulate a window layout not unlike Tkinter's packing mechanism. I am using Sizers for this, but keep on running into problems, so I'm wondering if what I want is possible at all. Here's a short description:

Let's say we have a frame f1 with three buttons A, B and C, in a horizontal row. There's also a frame f2 with three buttons 1, 2 and 3, tiled vertically. f1's buttons have f1 as parent, and f2's have f2 as parent. What I intend to do is make f2 the main frame, and add f1 to it as a subframe. So, the final window would roughly look like this:

button 1 (long)
button 2 (long)
button 3 (long)
buttons A, B and C in a row

I can easily do this if I use sizers properly. That is, 1, 2 and 3 go in one sizer, A, B and C in another, one sizer is added to the other, and all buttons have the same frame as their parent. This is how the examples in the demo seem to do it.

However, I would like to do this in the way described above, with two frames that are both parents to the buttons they contain, and they both have sizers. Is that possible? As said, I would like to emulate the Tkinter way of doing this, with frames added to frames.

Sorry if this is unclear. I'd post example code, but everything I tried so far yields the wrong layout and/or crashes the interpreter.

Thanks,

Howdy y'all,

Howdy!

button 1 (wide)
button 2 (wide)
button 3 (wide)
buttons A, B and C in a row

I can easily do this if I use sizers properly. That is, 1, 2
and 3 go in one sizer, A, B and C in another, one sizer is
added to the other, and all buttons have the same frame as
their parent. This is how the examples in the demo seem to
do it.

However, I would like to do this in the way described above,
with two frames that are both parents to the buttons they
contain, and they both have sizers.
Is that possible? As said, I would like to emulate the Tkinter
way of doing this, with frames added to frames.

First of all, I believe you probably mean wxPanel when you say
frame. Second, I prefer to do this kind of thing in a more
object-oriented way by defining a separate class for each panel.

See if this is what you want:

from wxPython.wx import *

class TallPanel(wxPanel):
    def __init__(self, parent):
        # create panel
        wxPanel.__init__(self, parent, id=-1)

        # create the controls
        btn1 = wxButton(self, -1, 'Wide Button 1')
        btn2 = wxButton(self, -1, 'Wide Button 2')
        btn3 = wxButton(self, -1, 'Wide Button 3')

        # create the sizer
        sizer = wxBoxSizer(wxVERTICAL)

        # add controls to sizer
        sizer.Add(btn1, 1, wxEXPAND)
        sizer.Add(btn2, 1, wxEXPAND)
        sizer.Add(btn3, 1, wxEXPAND)

        # enable sizer
        self.SetSizerAndFit(sizer)

## # on older versions of wxPython
## # replace SetSizerAndFit with:
## self.SetSizer(sizer)
## self.SetAutoLayout(True)
## sizer.Fit(self)
## sizer.SetSizeHints(self)

class WidePanel(wxPanel):
    def __init__(self, parent):
        # create panel
        wxPanel.__init__(self, parent, id=-1)

        # create the controls
        btn1 = wxButton(self, -1, 'Small 1')
        btn2 = wxButton(self, -1, 'Small 2')
        btn3 = wxButton(self, -1, 'Small 3')

        # create the sizer
        sizer = wxBoxSizer(wxHORIZONTAL)

        # add controls to sizer
        sizer.Add(btn1, 1, wxEXPAND)
        sizer.Add(btn2, 1, wxEXPAND)
        sizer.Add(btn3, 1, wxEXPAND)

        # enable sizer
        self.SetSizerAndFit(sizer)

class MyFrame(wxFrame):
    def __init__(self):
        wxFrame.__init__(self, None, -1, 'Sizer Demo')
        
        panel1 = TallPanel(self)
        panel2 = WidePanel(self)
        
        sizer = wxBoxSizer(wxVERTICAL)
        sizer.Add(panel1, 1, wxEXPAND)
        sizer.Add(panel2, 0, wxEXPAND)

        self.SetSizerAndFit(sizer)

class MyApp(wxApp):
    def OnInit(self):
        frame = MyFrame()
        frame.Show(1)
        return 1

if __name__ == '__main__':

    app = MyApp(0)
    app.MainLoop()

ยทยทยท

--- Hans Nowak <zephyr01@alltel.net> wrote:

=====
Donnal Walter
Arkansas Children's Hospital