How can I include static text in a StringVar() and still have it update to variable changes?
A StringVar does not bind with a Python name (what you'd call a variable), but with a Tkinter widget, like this:
a_variable= Tkinter.StringVar()an_entry= Tkinter.Entry(textvariable=a_variable)
From then on, any change of a_variable
through its .set
method will reflect in the an_entry
contents, and any modification of the an_entry
contents (e.g. by the user interface) will also update the a_variable
contents.
However, if that is not what you want, you can have two (or more) references to the same StringVar in your code:
var1= var2= Tkinter.StringVar()var1.set("some text")assert var1.get() == var2.get() # they'll always be equal