[Tutor] Python 3 and tkinter Radiobuttons
bobsmith327 at hotmail.com
Sun Oct 11 06:44:07 CEST 2009
Thanks for the reply. Unfortunately, even when I include a variable, all of the buttons start out selected. I noticed that this is the case when I create a StringVar (rather than an IntVar, where the buttons start out correctly unselected). So, here's another simple example where all of the radio buttons start out incorrectly selected:
from tkinter import *
root = Tk()
v = StringVar()
Radiobutton(root, text = "Test RadioButton 1", variable=v, value="1").grid(row = 0, column = 0, sticky = W)
Radiobutton(root, text = "Test RadioButton 2", variable=v, value="2").grid(row = 1, column = 0, sticky = W)
Any ideas on how to have a StringVar() associated with a group of Radiobutton objects where all of the radio buttons start off unselected?
> Date: Thu, 8 Oct 2009 20:43:21 -0400
> Subject: Re: [Tutor] Python 3 and tkinter Radiobuttons
> From: kent37 at tds.net
> To: bobsmith327 at hotmail.com
> CC: tutor at python.org
> On Thu, Oct 8, 2009 at 6:04 PM, bob smith <bobsmith327 at hotmail.com> wrote:
> > Hi. I’m using Tkinter to create a new Radiobutton in Python 3. However,
> > when I create the button, it starts off looking selected instead of
> > unselected (though it behaves correctly like an unselected Radiobutton). So
> > this means when I create a group of Radiobuttons they all look selected when
> > my program begins.
> You have to associate the Radiobuttons with a variable, for example:
> from tkinter import *
> root = Tk()
> v = IntVar()
> button = Radiobutton(root, text = "Test RadioButton", variable=v, value=1)
> button.grid(row = 0, column = 0, sticky = W)
> button = Radiobutton(root, text = "Test RadioButton2", variable=v, value=2)
> button.grid(row = 1, column = 0, sticky = W)
Hotmail: Trusted email with Microsoft’s powerful SPAM protection.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Tutor