Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > wxPython layout problem

Thread Tools

wxPython layout problem

Posts: n/a
I have the following code:
class MainFrame(wx.Frame):
    def __init__(self, parent, id, title):
        wx.Frame.__init__(self, parent, wx.ID_ANY, title,
        # build top area
        topSizer = self.buildTopPanel()
        # build input area
        inputSizer = self.buildInputPanel()

        mainSizer = wx.BoxSizer(wx.VERTICAL)
        mainSizer.Add(topSizer, 1, wx.EXPAND | wx.ALL, 5)
        mainSizer.Add(inputSizer, 1, wx.EXPAND | wx.ALL, 5)

        p = wx.Panel(self, wx.ID_ANY)

        s = wx.BoxSizer(wx.VERTICAL)
        s.Add(p, 1, wx.EXPAND)


    def buildTopPanel(self):
        p = wx.Panel(self, wx.ID_ANY)
        self.text = wx.TextCtrl(p, wx.ID_ANY, style=wx.TE_MULTILINE |
        sizer = wx.BoxSizer(wx.HORIZONTAL)
        sizer.Add(self.text, 1, wx.EXPAND)
        return sizer

    def buildInputPanel(self):
        # the area to enter text
        self.text2 = wx.TextCtrl(self, wx.ID_ANY, style=wx.TE_MULTILINE

        # panel to add button to
        p = wx.Panel(self, wx.ID_ANY)
        self.buttonClick = wx.Button(p, wx.ID_ANY, "Click")
        hsizer = wx.BoxSizer(wx.HORIZONTAL)
        hsizer.Add(self.buttonClick, 0, wx.ALIGN_CENTER)

        # add the text control and button panel
        box = wx.BoxSizer(wx.HORIZONTAL)
        box.Add(self.text2, 1, wx.EXPAND)
        box.Add(p, 0, wx.EXPAND)
        return box

if __name__ == "__main__":
    app = wx.PySimpleApp()
    frame = MainFrame(None, wx.ID_ANY, "Test")
.....there are two problems.
1) i want the sizer (that is returned from buildTopPanel()) to fill the
screen wide/tall. now the text control in it is very small in the
upper-left corner.

2) the scroll bars and borders on the text controls dont appear until i
mouse over them, any ideas?


Reply With Quote
Tim Roberts
Posts: n/a
"py" <(E-Mail Removed)> wrote:
>I have the following code:
>....there are two problems.
>1) i want the sizer (that is returned from buildTopPanel()) to fill the
>screen wide/tall. now the text control in it is very small in the
>upper-left corner.
>2) the scroll bars and borders on the text controls dont appear until i
>mouse over them, any ideas?

The panel you create in buildTopPanel has not been added to any sizer. So,
you have the odd condition that the self.text control is controlled by a
sizer, but its parent panel is not. The layout is confused.

You need to build this up bit by bit. The frame gets a panel. The panel
is controlled by a sizer. The panel will contain other panels, added to
the parent panel's sizer. The inner panels may need their own sizers. The
controls owned by the inner panels need to be added to the inner sizers.

The borders don't appear because parts of the panels are overlapping them
in strange ways.

Several folks have suggested that you create the controls from the outside
in, making sure that the control ownership is correct, and then as a
separate step, add those controls to sizers from the inside out. That
works for me, but some kind of structure is needed to make sure that
ownership and sizership are handled completely.

You might try posting on the wxPython mailing list,
- Tim Roberts, Removed)
Providenza & Boekelheide, Inc.
Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
wx/wxPython/wxPython.h & python24_d.lib problem Jolley Python 1 11-23-2006 08:02 AM
Choosing Layout: Css-Layout or Table-Layout ASP .Net 1 06-19-2006 10:06 AM
Oppinion regarding grid layout vs flow layout NWx ASP .Net 4 02-19-2004 08:56 PM
Converting from grid layout to flow layout. RobertH ASP .Net 1 11-04-2003 12:43 AM
DataList inside a Grid Layout Panel (<DIV>) item layout problem Rick Spiewak ASP .Net 3 08-26-2003 04:22 AM