Note that there are some explanatory texts on larger screens.

plurals
  1. POwxPython: Problems with GridBagSizer
    text
    copied!<p>I'm new to wxpython and it seems to be very powerful tool for building up GUI, but I have a question about GridBagSizer. Could you please tell me how to adjust the size of the items that are placed inside GridBagSizer to the size of the frame they are supposed to be placed in. I attached the sample at the end: the buttons from 8 to 13 go beyond the frame, but what I want is to make the size of the buttons automatically resize to fit the frame. Any advices and suggestions are appreciated.</p> <p>Best regards, Nikita</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(), label = num) grid.Add(button, pos, flag=wx.EXPAND) 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