]>
Commit | Line | Data |
---|---|---|
be05b434 RD |
1 | import wx |
2 | ||
3 | class RadioButtonFrame(wx.Frame): | |
4 | def __init__(self): | |
5 | wx.Frame.__init__(self, None, -1, 'Radio Example', | |
6 | size=(200, 200)) | |
7 | panel = wx.Panel(self, -1) | |
8 | radio1 = wx.RadioButton(panel, -1, "Elmo", pos=(20, 50), style=wx.RB_GROUP) | |
9 | radio2 = wx.RadioButton(panel, -1, "Ernie", pos=(20, 80)) | |
10 | radio3 = wx.RadioButton(panel, -1, "Bert", pos=(20, 110)) | |
11 | text1 = wx.TextCtrl(panel, -1, "", pos=(80, 50)) | |
12 | text2 = wx.TextCtrl(panel, -1, "", pos=(80, 80)) | |
13 | text3 = wx.TextCtrl(panel, -1, "", pos=(80, 110)) | |
14 | self.texts = {"Elmo": text1, "Ernie": text2, "Bert": text3} | |
15 | for eachText in [text2, text3]: | |
16 | eachText.Enable(False) | |
17 | for eachRadio in [radio1, radio2, radio3]: | |
18 | self.Bind(wx.EVT_RADIOBUTTON, self.OnRadio, eachRadio) | |
19 | self.selectedText = text1 | |
20 | ||
21 | def OnRadio(self, event): | |
22 | if self.selectedText: | |
23 | self.selectedText.Enable(False) | |
24 | radioSelected = event.GetEventObject() | |
25 | text = self.texts[radioSelected.GetLabel()] | |
26 | text.Enable(True) | |
27 | self.selectedText = text | |
28 | ||
29 | if __name__ == '__main__': | |
30 | app = wx.PySimpleApp() | |
31 | RadioButtonFrame().Show() | |
32 | app.MainLoop() |