Message296100
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()
``` |
|
Date |
User |
Action |
Args |
2017-06-15 14:37:56 | Javier Dehesa | set | recipients:
+ Javier Dehesa, paul.moore, tim.golden, zach.ware, steve.dower |
2017-06-15 14:37:56 | Javier Dehesa | set | messageid: <1497537476.52.0.54900558235.issue30678@psf.upfronthosting.co.za> |
2017-06-15 14:37:56 | Javier Dehesa | link | issue30678 messages |
2017-06-15 14:37:56 | Javier Dehesa | create | |
|