While box sizers are nice to work with, grid bag sizers are also nice. They allow controls to be put in a grid. For example, say we wanted four buttons arranged in a square. This can be done with a grid bag sizer. Let's take a look at how it is done: from wxPython.wx import * class SizerFrame ( wxFrame ): def __init__ ( self ): wxFrame.__init__ ( self, None, -1, 'Sizers' ) self.panel = wxPanel ( self, -1 ) application = wxPySimpleApp() As you can see, it's not very hard. Let's manipulate our grid a bit. Let's widen the horizontal border to ten pixels instead of two and make the buttons expandable. Let's also get rid of the second button and make the first button take up the whole row: from wxPython.wx import * class SizerFrame ( wxFrame ): def __init__ ( self ): wxFrame.__init__ ( self, None, -1, 'Sizers' ) self.panel = wxPanel ( self, -1 ) self.Show ( True ) application = wxPySimpleApp() Notice that every cell in the grid had the same size. We can change that using a flexible grid sizer: from wxPython.wx import * class SizerFrame ( wxFrame ): def __init__ ( self ): wxFrame.__init__ ( self, None, -1, 'Sizers' ) self.panel = wxPanel ( self, -1 ) self.Show ( True ) application = wxPySimpleApp() Conclusion That's it. You should now know enough about sizers to create organized applications instead of applications featuring controls thrown around the frame. Sizers make a lot more sense than absolute positioning and eliminate a lot of the work involved in the absolute positioning of controls. You also know a few more controls, enough to do a few small applications.
blog comments powered by Disqus |
|
|
|
|
|
|
|