Can't tkinter.widget.configure(text="our text")
be used for all widgets? What is the advantage, or the main purpose of using:
var_cls = tkinter.StringVar()
tkinter.widget.configure(textvariable=var_cls)
Is it that var_cls
can be more easily shared among methods/classes etc?
Example with a Variable class:
import tkinter as tk
root = tk.Tk()
var = tk.StringVar(value="This will be on the label.")
tk.Label(root, textvariable=var).pack()
root.mainloop()
Example without a Variable class:
import tkinter as tk
root = tk.Tk()
tk.Label(root, text="This will be on the label.").pack()
root.mainloop()
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…