Returning to Coding
Returning to Coding

Reputation: 345

wxPython - Can't get buttons to resize

I am new to wxPython and I have a very basic question about getting buttons to resize.

Im working on a mac with python 2.7.3 and using wxPython 2.8.10.1

I have been working with it for a few days and I think I understand the sizer layout methods. I am trying to get a grid of buttons to grow in size when the window is expanded. I know its a basic issue but I have spent hours.

I cant figure out how to get a screen shot image here but the buttons show fine and then stay the same size when the window is enlarged.

Thanks.

#!/usr/bin/env python
import wx
class Example(wx.Frame):

def __init__(self, *args, **kw):
    super(Example, self).__init__(*args, **kw) 
    self.InitUI()
    self.SetSize((550, 160))
    self.SetTitle("Label of Grids")
    self.Centre()
    self.Show()     

def InitUI(self):

    pnl = wx.Panel(self)       
    grid = wx.GridBagSizer(3, 3)
    for r in range(6):
        for c in range (4):
            buttonname = str(r)+"_"+str(c)
            labeltxt = "(row= "+str(r)+", col= "+str(c)+")"
            grid.Add(wx.Button(pnl, name = buttonname,label=labeltxt), (r, c),flag =wx.EXPAND)
    pnl.SetSizer(grid)

def main():

    app = wx.App()
    Example(None)
    app.MainLoop()    


if __name__ == '__main__':
    main()  

Upvotes: 2

Views: 1300

Answers (1)

g.d.d.c
g.d.d.c

Reputation: 48028

When you're using GridBagSizer's you need to make calls to the AddGrowableCol(idx) and AddGrowableRow(idx) methods in order to allow individual rows and columns in the Grid to be fluid in size.

Upvotes: 1

Related Questions