[Tkinter-discuss] initial state of radiobutton

Fredrik Lundh fredrik at pythonware.com
Sun Aug 17 15:08:43 CEST 2008

Iain Day wrote:

> def edit_preferences(event=None):
>     prefs = Preferences(master, title="Preferences")
> class Preferences(tkSimpleDialog.Dialog):
>     def body(self, master):
>         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')

           self.angles = angles # keep a reference to the variable

>         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)

Widgets don't keep references to their option values, so unless you 
explicitly keep a reference to the variable yourself (e.g. via an 
instance attribute, as above), it'll be removed at the end of the method.


More information about the Tkinter-discuss mailing list