Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You must allow the columns to grow by calling <code>AddGrowableCol</code>:</p> <pre><code> for i in range(11): grid.AddGrowableCol(i) </code></pre> <p>Now, they can grow, but they won't shrink beyond their initial size! So you should also reduce their starting size:</p> <pre><code> for num, pos in nums: button = wx.Button(panel, wx.NewId(), size=(10,-1), label = num) #original code was: button = wx.Button(panel, wx.NewId(), label = num) grid.Add(button, pos, flag=wx.EXPAND) </code></pre> <p>Here is the complete listing:</p> <pre><code>import wx class Frame ( wx.Frame ): def __init__( self ): wx.Frame.__init__ ( self, None, id = wx.ID_ANY, title = wx.EmptyString, pos = wx.DefaultPosition, size = wx.Size( 500,300 ), style = wx.DEFAULT_FRAME_STYLE &amp; ~ (wx.MAXIMIZE_BOX|wx.MINIMIZE_BOX|wx.RESIZE_BORDER) ) nums = (('1',(0,3)), ('2',(2,3)), ('14', (3,3)), ('15',(4,3)), ('16',(5,3)), ('17',(6,3)), ('18',(7,3)), ('3',(1,0)), ('4',(1,1)), ('5',(1,2)), ('6',(1,3)), ('7',(1,4)), ('8',(1,5)), ('9',(1,6)), ('10',(1,7)), ('11',(1,8)), ('12',(1,9)), ('13',(1,10))) panel = wx.Panel(self,-1) panel.SetBackgroundColour("green") grid = wx.GridBagSizer(2,2) for num, pos in nums: button = wx.Button(panel, wx.NewId(), size=(10,-1), label = num) grid.Add(button, pos, flag=wx.EXPAND) for i in range(11): grid.AddGrowableCol(i) bs2 = wx.BoxSizer(wx.VERTICAL) bs2.Add(grid, 0, wx.EXPAND,0) panel.SetSizer(bs2) panel.Layout() self.mainSizer = wx.BoxSizer(wx.VERTICAL) self.mainSizer.Add(panel, 0, wx.EXPAND, 0) self.SetSizer(self.mainSizer) self.Layout() if __name__=='__main__': app=wx.PySimpleApp() app.frame = Frame() app.frame.Center() app.frame.Show(True) app.MainLoop() </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload