WxPython GridSizer - work with empty cells

I am making my first foray into GUI programming and I am trying to deal with wxPython. I am trying to use wxGlade, but that turns out to be a bit of a mistake.

I am making a layout using a GridSizer.

I found out that every time you add something to the sizer, it is placed in the next cell. This means that if you have an empty cell, you need to fill in something. I'm right?

This is the layout I'm going to do (wxGlade screenshot):

wxGlade layout screenshot

The problem is that I am generating code from this:

enter image description here

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) 

Apparently, because the Down button is entered in the 7th cell instead of the 8th.

What is the standard way to deal with this? Would you put some kind of dummy widget to fill an empty cell? If so, which widget? Or am I using the wrong kind of sizer?

Thanks!

+4
source share
2 answers

As you said ... adding a dummy widget (empty static text) works well. You can also use AddMany () instead of several add ().

 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) ] ) 
+9
source

I'm more familiar with using (0,0) , which means adding a stretchable size to the sizer. Thus, you can create one object, for example empty_cell = (0,0) , and then insert it into empty_cell wherever the empty space is needed in your sizer (where, for example, wx.StaticText is used in the accepted answer).

+2
source

Source: https://habr.com/ru/post/1337621/


All Articles