[Tkinter-discuss] initial state of radiobutton
iain at day-online.org.uk.invalid
Sat Aug 16 13:34:23 CEST 2008
Sorry about that. The code below does work, however, in my case its a
little more complex. I'll try and explain. I've put most of the code
into different modules which get imported in the usual way, so I have
one that has all the classes for the menu bar. There is also a class in
here which generates the tkSimpleDialog for the preferences. Is is here
that I've got the bit of code I posted below.
__main__.angles is set correctly, and if I do:
I get the correct result.
I'm a little confused. Also if I put angles into an Entry widget it is
Thanks for your help,
Michael O'Donnell wrote:
> 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)
> ...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.
> On Fri, Aug 15, 2008 at 6:19 AM, Iain Day
> <iain at day-online.org.uk.invalid> wrote:
>> 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,
>> 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?
>> Tkinter-discuss mailing list
>> Tkinter-discuss at python.org
More information about the Tkinter-discuss