wxPython GridSizer - si tratta di celle vuote
-
27-10-2019 - |
Domanda
Sto facendo la mia prima incursione nella programmazione GUI, e sto cercando di fare i conti con wxPython. Sto cercando di usare wxGlade, ma è svolta a essere un po 'buggy.
Sto facendo un layout utilizzando GridSizer.
Ho lavorato fuori che ogni volta che si aggiunge qualcosa al sizer, esso viene messo nella cella accanto. Questo significa che se si dispone di una cella vuota, è necessario riempirlo con qualcosa. Ho ragione?
Questo è il layout Vado a fare (wxGlade screenshot):
Il problema è che la generazione di codice da che ottengo questo:
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)
A quanto pare perché il pulsante "Down" è sempre messo in 7 ° cella invece del 8.
Qual è il modo standard di fare con questo? Volete mettere una sorta di manichino widget nella per riempire la cella vuota? Se è così che widget di? O sto usando il tipo sbagliato di sizer?
Grazie!
Soluzione
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) ] )
Altri suggerimenti
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).