Fredrik Lundh wrote:
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.

Okay, thanks. Not quite sure I follow though, later in my code I have

tk.Label(files, text="Working dir: ").grid(row=0, column=0, sticky=tk.E)
tk.Entry(files, textvariable=workdir).grid(row=0, column=1, sticky=tk.W)

and this worked okay, without the self.var = var bit. Is there a difference between the two?

Thanks,

Iain

_______________________________________________
Tkinter-discuss mailing list
Tkinter-discuss@python.org
http://mail.python.org/mailman/listinfo/tkinter-discuss

Reply via email to