Deselecting Radio Buttons

Matthew Dixon Cowles matt at mondoinfo.com
Mon Oct 2 20:57:55 EDT 2000


On Mon, 2 Oct 2000 17:20:13 EDT, OneDay at A.Time <OneDay at A.Time> wrote:

>It must be possible to deselect a radio button after selecting it.
>Would someone please tell me how?

>PMVar = IntVar()
>PMBut = Radiobutton(root, text="Select for P.M.", value=2, \
>  variable=PMVar, padx=50)
>PMBut.grid(row=1, column=2,sticky=E)
>PM = PMVar.get()

There are two ways to set radio buttons under program control. The
buttons have select() and deselect() methods. Those methods work fine
except that if you use deselect(), the related variable can take on a
value you may not expect. It's simpler in my experience to control
which button is selected by setting the value of the variable. If you
want no radio button to be selected, set the variable to a value that
isn't one of the radio buttons' values. In your case,

PMVar.set(0)

should work.

Regards,
Matt



More information about the Python-list mailing list