How to create a radio button (Phoenix)
Keywords : Radio button.
Contents
Introduction :
wx.RadioButton is a widget that allows the user to select a single exclusive choice from a group of options.
A group of radio buttons is defined by having the first RadioButton in the group contain the wx.RB_GROUP style.
All other RadioButtons defined after the first RadioButton with this style flag is set will be
added to the function group of the first RadioButton.
Declaring another RadioButton with the wx.RB_GROUP flag will start a new radio button group.
wx.RadioButton styles :
- wx.RB_GROUP
- wx.RB_SINGLE
wx.RadioButton methods |
|
bool GetValue() |
returns True or False depending on the selection state |
SetValue(bool state) |
RadioButton |
(info by ZetCode / Jan Bodnar).
Demonstrating :
Tested py3.x, wx4.x and Win10.
Are you ready to use some samples ?
Test, modify, correct, complete, improve and share your discoveries !
Sample one
1 # sample_one.py
2
3 """
4
5 Author : Jan Bodnar
6 Website : zetcode.com
7
8 """
9
10 import wx
11
12 # class MyFrame
13 # class MyApp
14
15 #---------------------------------------------------------------------------
16
17 class MyFrame(wx.Frame):
18 def __init__(self, parent, id, title):
19 wx.Frame.__init__(self, parent, id, title,
20 wx.DefaultPosition, wx.Size(300, 150))
21
22 self.SetIcon(wx.Icon('./icons/icon_wxWidgets.ico', wx.BITMAP_TYPE_ICO))
23 self.SetMinSize((300, 150))
24
25 #------------
26
27 panel = wx.Panel(self, -1)
28
29 self.rb1 = wx.RadioButton(panel, -1, 'Value A', (10, 10), style=wx.RB_GROUP)
30 self.rb2 = wx.RadioButton(panel, -1, 'Value B', (10, 30))
31 self.rb3 = wx.RadioButton(panel, -1, 'Value C', (10, 50))
32
33 #------------
34
35 self.Bind(wx.EVT_RADIOBUTTON, self.SetVal, id=self.rb1.GetId())
36 self.Bind(wx.EVT_RADIOBUTTON, self.SetVal, id=self.rb2.GetId())
37 self.Bind(wx.EVT_RADIOBUTTON, self.SetVal, id=self.rb3.GetId())
38
39 #------------
40
41 self.statusbar = self.CreateStatusBar(3)
42
43 #------------
44
45 self.SetVal(True)
46
47 #-----------------------------------------------------------------------
48
49 def SetVal(self, event):
50 state1 = str(self.rb1.GetValue())
51 state2 = str(self.rb2.GetValue())
52 state3 = str(self.rb3.GetValue())
53 self.statusbar.SetStatusText(state1,0)
54 self.statusbar.SetStatusText(state2,1)
55 self.statusbar.SetStatusText(state3,2)
56
57 #---------------------------------------------------------------------------
58
59 class MyApp(wx.App):
60 def OnInit(self):
61 frame = MyFrame(None, -1, 'wx.RadioButton')
62 frame.Center()
63 frame.Show(True)
64
65 return True
66
67 #---------------------------------------------------------------------------
68
69 app = MyApp(0)
70 app.MainLoop()
Download source
Additional Information
Link :
https://wiki.wxpython.org/TitleIndex
Thanks to
Jan Bodnar (sample_one.py coding), the wxPython community...
About this page
Date(d/m/y) Person (bot) Comments :
27/12/20 - Ecco (Created page for wxPython Phoenix).
Comments
- blah, blah, blah....