Apr-18-2022, 04:38 AM
The view should not save data. Your data model should save/restore data.
I cannot find anything in tkinter that returns a list of variables, but you can get all the variables for a window in Tk.
https://tcl.tk/man/tcl8.6/TclCmd/variable.htm
In this example I make a bunch of variables and forget to keep a handle to the variable. I use a call to tk to get a list of all variables that match the pattern "PY_*" and use these names to get the variable values.
I cannot find anything in tkinter that returns a list of variables, but you can get all the variables for a window in Tk.
https://tcl.tk/man/tcl8.6/TclCmd/variable.htm
In this example I make a bunch of variables and forget to keep a handle to the variable. I use a call to tk to get a list of all variables that match the pattern "PY_*" and use these names to get the variable values.
import tkinter as tk root = tk.Tk() tk.Entry(root, textvariable=tk.StringVar(root, "One")).pack() tk.Entry(root, textvariable=tk.IntVar(root, 1)).pack() tk.Entry(root, textvariable=tk.DoubleVar(root, 1.0)).pack() for var in root.tk.call("info", "vars", "PY_*"): print(var, type(var), root.tk.globalgetvar(var))
Output:PY_VAR0 <class '_tkinter.Tcl_Obj'> One
PY_VAR1 <class '_tkinter.Tcl_Obj'> 1
PY_VAR2 <class '_tkinter.Tcl_Obj'> 1.0