This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Javier Dehesa
Recipients Javier Dehesa, paul.moore, steve.dower, tim.golden, zach.ware
Date 2017-06-15.14:37:56
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1497537476.52.0.54900558235.issue30678@psf.upfronthosting.co.za>
In-reply-to
Content
When you build a Tkinter interface with variables, if tkinter.Tk.mainloop is called from a different function that the one creating the variable objects, then in some cases the widgets associated with the variables will not be set to the right value. I have not been able to find a consistent pattern, but I have some examples.

The following script works correctly:
```
import tkinter as tk
from tkinter import ttk

def make_var_cb(root):
    v = tk.BooleanVar(root, True)
    cb = ttk.Checkbutton(root, text='Checkbutton', variable=v)
    cb.pack()
    root.mainloop()

if __name__ == '__main__':
    root = tk.Tk()
    make_var_cb(root)
```

But the following does not (the result is shown in the attached image):
```
import tkinter as tk
from tkinter import ttk

def make_var_cb(root):
    v = tk.BooleanVar(root, True)
    cb = ttk.Checkbutton(root, text='Checkbutton', variable=v)
    cb.pack()

if __name__ == '__main__':
    root = tk.Tk()
    make_var_cb(root)
    root.mainloop()
```

However, the following _does_ work again:
```

def make_var(root):
    return tk.BooleanVar(root, True)

def make_cb(root, v):
    return ttk.Checkbutton(root, text='Checkbutton', variable=v)

if __name__ == '__main__':
    root = tk.Tk()
    v = make_var(root)
    cb = make_cb(root, v)
    cb.pack()
    root.mainloop()
```
History
Date User Action Args
2017-06-15 14:37:56Javier Dehesasetrecipients: + Javier Dehesa, paul.moore, tim.golden, zach.ware, steve.dower
2017-06-15 14:37:56Javier Dehesasetmessageid: <1497537476.52.0.54900558235.issue30678@psf.upfronthosting.co.za>
2017-06-15 14:37:56Javier Dehesalinkissue30678 messages
2017-06-15 14:37:56Javier Dehesacreate