Dynamic resizing
I am trying to make a wxChoice show/hide/resize a wxTextCtrl and wxButton depending on the item selected in the wxChoice. The 3 widgets are in a horizontal BoxSizer. When the wxTextCtrl resizes, the wxButton should move so that it is just to the right of the wxTextCtrl.
Here is my EVT_CHOICE handler:
def OnChoice(self, event):
sel = event.GetSelection()
if sel == 0:
show = False
t_len = 40
elif sel == 1:
show = True
t_len = 40
else: # sel == 2
show = True
t_len = 120
self.d_sizer.Show(self.text_ctrl_1, show)
self.d_sizer.Show(self.button_3, show)
self.text_ctrl_1.SetSize(wx.Size(t_len, -1))
self.d_sizer.Layout()
The show/hide functionality works OK. However the resizing doesn’t.
If I include the Layout() call, the wx.TextCtrl widget momentarily expands but then immediately shrinks again. If I leave out the Layout() call, the wxTextCtrl widget expands and contracts OK, but the button doesn’t move in and out with it.
Is it possible to achieve the required behaviour?
I did wonder if I could use the wxSizer.Detach() method to detach the button and then add it again, but the Detach method does not appear to be supported in wxPython 2.5.1.5, even though it appears in the wxWidgets documentation.
Using wxPython-2.5.1.5, Python-2.3.3, Win98.
regards
Richard Townsend