StringVar()
is a class from tkinter. It's used so that you can easily monitor changes to tkinter variables if they occur through the example code provided:
def callback(*args):
print "variable changed!"
var = StringVar()
var.trace("w", callback)
var.set("hello")
This code will check if var
has been over-written (this mode is defined by the w
in var.trace("w", callback)
.
A string such as "hello"
is just a data type, it can be manipulated and read and all sorts, the primary difference is that if the string was assigned to a variable, such as a = 'hello'
, there is no way of telling if a
has changed (i.e if now a = 'hello'
) unless you do a comparison somewhere which could be messy.
Put it simply: StringVar()
allows you to easily track tkinter variables and see if they have been read, overwritten, or if they even exist which you can't easily do with just a typical a = 'hello'
Helpful : http://effbot.org/tkinterbook/variable.htm
Edit : Replaced 'variables' with 'tkinter variables' where appropriate as per @Bryan Oakley's suggestion