wxPython: GridBagSizer, EXPAND, and HtmlListBox

Adam Endicott leftwing17 at gmail.com
Mon Jun 6 17:25:39 EDT 2005


I'm  having some trouble using an HtmlListBox with a GridBagSizer. I'm
not sure how best to explain what's happening, but it seems that every
time my frame gets resized, the HtmlListBox grows taller, even when the
resize is only horizontal, or makes the frame smaller. I'm pretty new
to GUI layout and wxPython, so hopefully I'm doing something obviously
wrong. Here's a short runnable code sample showing my basic layout (I'm
using python 2.3.3 and wxPython 2.6 running on windows XP pro):

-----Start Code-----

import wx

class TestFrame(wx.Frame):
    def __init__(self):
        app = wx.PySimpleApp()
        wx.Frame.__init__(self, None, -1)
        p = wx.Panel(self, -1)
        gbs = wx.GridBagSizer(5, 5)
        gbs.Add(wx.Button(p, -1), (0, 0), span=(1, 2), flag=wx.EXPAND)
        hlb = wx.HtmlListBox(p, -1)
        gbs.Add(hlb, (1, 0), span=(4, 1), flag=wx.EXPAND)
        gbs.Add(wx.Button(p, -1), (1, 1), flag=wx.EXPAND)
        gbs.Add(wx.Button(p, -1), (2, 1), flag=wx.EXPAND)
        gbs.Add(wx.Button(p, -1), (3, 1), flag=wx.EXPAND)
        gbs.Add(wx.Button(p, -1), (4, 1), flag=wx.EXPAND)
        gbs.AddGrowableRow(2)
        gbs.AddGrowableCol(1)
        p.SetSizerAndFit(gbs)
        self.SetClientSize(p.GetSize())
        self.Show(True)
        wx.EVT_SIZE(hlb, self.onSize)
        app.MainLoop()

    def onSize(self, event):
        print event.GetSize()

if __name__ == '__main__':
    TestFrame()

-----End Code-----

If you run that and try to resize the window by dragging an edge, the
HtmlListBox just goes crazy and keeps getting bigger (try dragging the
right edge back and forth).

It does the same thing if I replace the HtmlListBox with a wx.Panel or
even a wx.Window, but not with a wx.ListBox, or wx.Button. The effect
I'm trying to accomplish is basically what you get if you sub in a
wx.ListBox, (but I need the HtmlListBox because I want to put a small
image next to the strings in the list).

Removing the wx.EXPAND flag on the HtmlListBox (at line 11) solves the
weird resizing, except that now the HtmlListBox doesn't fill the space
it needs to.

Does anyone know what's going on here, or how I can get this to work?




More information about the Python-list mailing list