I'm making my first foray into GUI programming, and I'm trying to get to grips with wxPython. I'm trying to use wxGlade, but it's turning out to be a bit buggy.
I'm making a layout using GridSizer.
I've worked out that every time you add something to the sizer, it gets put in the next cell. This means if you have an empty cell, you need to fill it with something. Am I right?
This is the layout I'm going for (wxGlade screenshot):
The problem is, generating code from that I get this:
grid_sizer_1 = wx.GridSizer(3, 3, 0, 0)
grid_sizer_1.Add(self.button_last_page, 0, wx.ALIGN_CENTER_HORIZONTAL|wx.ALIGN_CENTER_VERTICAL, 0)
grid_sizer_1.Add(self.button_up, 0, wx.ALIGN_BOTTOM|wx.ALIGN_CENTER_HORIZONTAL, 0)
grid_sizer_1.Add(self.button_next_page, 0, wx.ALIGN_CENTER_HORIZONTAL|wx.ALIGN_CENTER_VERTICAL, 0)
grid_sizer_1.Add(self.button_left, 0, wx.ALIGN_RIGHT|wx.ALIGN_CENTER_VERTICAL, 0)
grid_sizer_1.Add(self.button_select, 0, wx.ALIGN_CENTER_HORIZONTAL|wx.ALIGN_CENTER_VERTICAL, 0)
grid_sizer_1.Add(self.button_right, 0, wx.ALIGN_CENTER_VERTICAL, 0)
grid_sizer_1.Add(self.button_down, 0, wx.ALIGN_CENTER_HORIZONTAL, 0)
Seemingly because the "Down" button is getting put in the 7th cell instead of the 8th.
What is the standard way of dealing with this? Would you put some kind of dummy widget in to fill the empty cell? If so which widget? Or am I using the wrong kind of sizer?
Thanks!
As you said... adding a dummy widget (blank static text) works well. You can also use AddMany() instead of multiple add()'s.
grid_sizer_1 = wx.GridSizer(3, 3, 0, 0)
grid_sizer_1.AddMany( [
(self.button_last_page, 0, wx.ALIGN_CENTER_HORIZONTAL|wx.ALIGN_CENTER_VERTICAL),
(self.button_up, 0, wx.ALIGN_BOTTOM|wx.ALIGN_CENTER_HORIZONTAL),
(self.button_next_page, 0, wx.ALIGN_CENTER_HORIZONTAL|wx.ALIGN_CENTER_VERTICAL),
(self.button_left, 0, wx.ALIGN_RIGHT|wx.ALIGN_CENTER_VERTICAL),
(self.button_select, 0, wx.ALIGN_CENTER_HORIZONTAL|wx.ALIGN_CENTER_VERTICAL),
(self.button_right, 0, wx.ALIGN_CENTER_VERTICAL),
(wx.StaticText(self, -1, ''), 0, wx.EXPAND),
(self.button_down, 0, wx.ALIGN_CENTER_HORIZONTAL) ] )
I am more familiar with using (0,0)
which means add stretchable size to the sizer. So, one would create a single object like empty_cell = (0,0)
and then stick in empty_cell
everywhere that empty space is needed in your sizer (where for example the wx.StaticText is used in the accepted answer).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With