Reputation: 392
I woul like to have a textctrl which is placed inside a horizontal box. I made this atm using this code:
self.myTextCtrl = wx.TextCtrl(panel, -1, "bleh")
self.vbox.Add(self.myTextCtrl, proportion = 1)
This code prints my label in the screen.
However, i have a radiobutton above it (defaults to false) and when i set it to true, i want the box to show. I tried to call self.myTextCtrl.Hide()
(The hiding occurs in an event triggered by the radio butto switching)
but this results in the textctrl not being able to be loaded later...
Some1 told me it had to do with wxpython compiling your program without the box present since you disabe it, but i cant find info on that on the web.
Please help.
Upvotes: 0
Views: 2411
Reputation: 33071
I whipped up a quick and dirty example. Radio buttons cannot be "unchecked" once they are set to True unless you're using them in a group, so I included an example using a CheckBox widget as well. I also added a blank text control as something needed to accept focus without setting off the events for the other widgets:
import wx
########################################################################
class MyPanel(wx.Panel):
""""""
#----------------------------------------------------------------------
def __init__(self, parent):
"""Constructor"""
wx.Panel.__init__(self, parent)
txt = wx.TextCtrl(self)
radio1 = wx.RadioButton( self, -1, " Radio1 ")
radio1.Bind(wx.EVT_RADIOBUTTON, self.onRadioButton)
self.hiddenText = wx.TextCtrl(self)
self.hiddenText.Hide()
self.checkBtn = wx.CheckBox(self)
self.checkBtn.Bind(wx.EVT_CHECKBOX, self.onCheckBox)
self.hiddenText2 = wx.TextCtrl(self)
self.hiddenText2.Hide()
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(txt, 0, wx.ALL, 5)
sizer.Add(radio1, 0, wx.ALL, 5)
sizer.Add(self.hiddenText, 0, wx.ALL, 5)
sizer.Add(self.checkBtn, 0, wx.ALL, 5)
sizer.Add(self.hiddenText2, 0, wx.ALL, 5)
self.SetSizer(sizer)
#----------------------------------------------------------------------
def onRadioButton(self, event):
""""""
print "in onRadioButton"
self.hiddenText.Show()
self.Layout()
#----------------------------------------------------------------------
def onCheckBox(self, event):
""""""
print "in onCheckBox"
state = event.IsChecked()
if state:
self.hiddenText2.Show()
else:
self.hiddenText2.Hide()
self.Layout()
########################################################################
class MyFrame(wx.Frame):
""""""
#----------------------------------------------------------------------
def __init__(self):
"""Constructor"""
wx.Frame.__init__(self, None, title="Radios and Text")
panel = MyPanel(self)
self.Show()
if __name__ == "__main__":
app = wx.App(False)
f = MyFrame()
app.MainLoop()
Upvotes: 1