[wxPython-users] Unselecting radiobuttons
Ken Schutte
kschutte at csail.mit.edu
Sat Mar 1 13:25:47 PST 2008
Marc Tompkins wrote:
> On Sat, Mar 1, 2008 at 12:13 PM, Ken Schutte <kschutte at csail.mit.edu
> <mailto:kschutte at csail.mit.edu>> wrote:
>
> For a group of radiobuttons (or a radiobox), is there a way to make none
> of them selected?
>
>
> I tried to do something like this myself a while back; I beat my head
> against it for a while, and then realized that it goes against the
> entire philosophy of radiobuttons. So I went with what seemed to me
> like a more consistent approach: a radiobutton for "None of the above".
>
Maybe it's just personal opinion, but I do think there are scenarios
where it makes sense to have no radio buttons selected.
But, anyways... I did something related that will work for now - create
a third button, but keep it hidden with .Hide(). In case anyone's
interested, the example I included before is changed as below, and does
basically what I want.
#!/usr/bin/python
import wx
app = wx.PySimpleApp()
frame = wx.Frame(None,-1,"TESTING")
def go(ev):
print rb1.GetValue(), rb2.GetValue(), rb3.GetValue()
rb3.SetValue(True)
print rb1.GetValue(), rb2.GetValue(), rb3.GetValue()
p = wx.Panel(frame,-1)
rb1 = wx.RadioButton(p,-1,"A")
rb2 = wx.RadioButton(p,-1,"B")
rb3 = wx.RadioButton(p,-1,"C")
ID_BUTTON = 201
b = wx.Button(p, ID_BUTTON, "GO")
wx.EVT_BUTTON(p, ID_BUTTON, go)
sizer = wx.BoxSizer(wx.HORIZONTAL)
sizer.Add(rb1,1,wx.EXPAND)
sizer.Add(rb2,1,wx.EXPAND)
sizer.Add(rb3,1,wx.EXPAND)
sizer.Add(b,1,wx.EXPAND)
p.SetSizer(sizer)
frame.Show(1)
rb3.Hide()
app.MainLoop()
More information about the wxpython-users
mailing list