Unselecting radiobuttons

Ken Schutte kschutte at csail.mit.edu
Sat Mar 1 12:13:50 PST 2008


For a group of radiobuttons (or a radiobox), is there a way to make none 
of them selected?

I've been searching for an answer to this, and it seems you could just 
do SetValue(False), according to:

http://lists.wxwidgets.org/archive/wxPython-users/msg59923.html

However, I have not gotten this to work.  I have been testing on a 
simple test case which I'll paste below.  I'd like pressing the button 
to deselect both radiobuttons, but it does nothing.  Anyone have a 
suggestion?

thanks,
Ken



#!/usr/bin/python
import wx
app = wx.PySimpleApp()
frame = wx.Frame(None,-1,"TESTING")

def go(ev):
     print "------ go -------"
     print rb1.GetValue(), rb2.GetValue()
     rb1.SetValue(False)
     rb2.SetValue(False)
     print rb1.GetValue(), rb2.GetValue()

p = wx.Panel(frame,-1)
rb1 = wx.RadioButton(p,-1,"A")
rb2 = wx.RadioButton(p,-1,"B")

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(b,1,wx.EXPAND)

p.SetSizer(sizer)

frame.Show(1)
app.MainLoop()





More information about the wxpython-users mailing list