[Tkinter-discuss] initial state of radiobutton
Michael O'Donnell
michael.odonnell at uam.es
Fri Aug 15 01:38:48 CEST 2008
Dear Iain,
Makes it easier to test your code if you provide
a standalone example.
I modified your code as follows to get it to run:
import Tkinter as tk
master = tk.Tk()
settings = tk.LabelFrame(master, text="Settings")
settings.grid(row=0, column=0)
tk.Label(settings, text="Angular Units: ").grid(row=0, column=0, sticky=tk.E)
angles = tk.StringVar(value='radians')
tk.Radiobutton(settings, text="Degrees", variable=angles,
value='degrees').grid(row=0, column=1)
tk.Radiobutton(settings, text="Radians", variable=angles,
value='radians').grid(row=0, column=2)
master.mainloop()
...and on my Macosx running python 2.5.2 it runs fine, with buttons selected.
My bet is that angles is not in fact set, or is not set
to one of 'degrees' or 'radians'. Put a print statement to
see what value __main__.angles has at the point of
setting the variable angles.
Mick
On Fri, Aug 15, 2008 at 6:19 AM, Iain Day
<iain at day-online.org.uk.invalid> wrote:
> Hi,
>
> I'm trying to create a preferences dialog. At the moment, I'm just reading a
> config file using ConfigParser and displaying this in a tkSimpleDialog.
>
> I've got some Entry widgets working okay, but I can't get the radiobuttons
> to work. The code is:
>
> import Tkinter as tk
>
> settings = tk.LabelFrame(master, text="Settings")
> settings.grid(row=0, column=0)
>
> tk.Label(settings, text="Angular Units: ").grid(row=0, column=0,
> sticky=tk.E)
>
> angles = tk.StringVar(value=__main__.angles)
>
> tk.Radiobutton(settings, text="Degrees", variable=angles,
> value='degrees').grid(row=0, column=1)
>
> tk.Radiobutton(settings, text="Radians", variable=angles,
> value='radians').grid(row=0, column=2)
>
> When I run this, angles is set to degrees but I don't get the radiobutton
> active (either of them).
>
> What am I doing wrong?
>
> Thanks,
>
> Iain
>
> _______________________________________________
> Tkinter-discuss mailing list
> Tkinter-discuss at python.org
> http://mail.python.org/mailman/listinfo/tkinter-discuss
>
More information about the Tkinter-discuss
mailing list