[wxPython-users] Unselecting radiobuttons

C M cmpython at gmail.com
Sat Mar 1 15:54:44 PST 2008


On Sat, Mar 1, 2008 at 3:13 PM, Ken Schutte <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'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 =3D wx.PySimpleApp()
> frame =3D 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 =3D wx.Panel(frame,-1)
> rb1 =3D wx.RadioButton(p,-1,"A")
> rb2 =3D wx.RadioButton(p,-1,"B")
>
> ID_BUTTON =3D 201
> b =3D wx.Button(p, ID_BUTTON, "GO")
> wx.EVT_BUTTON(p, ID_BUTTON, go)
>
> sizer =3D 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()
>
>
It works for me (on WinXP, wxPython 2.8.7.1, Python 2.5).

cm
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.wxwidgets.org/pipermail/wxpython-users/attachments/200803=
01/2492cafc/attachment.htm


More information about the wxpython-users mailing list