Issue with 'StringVar' in Python Program Issue with 'StringVar' in Python Program tkinter tkinter

Issue with 'StringVar' in Python Program


I think you might need to call Tk() explicitly before invoking StringVar.

Just do this:

from Tkinter import *Tk() # Add thisvar = StringVar()var.set('test');


I've never done anything with Tkinter myself, but here it looks like this StringVar class inherits from a base Variable class, as you can see in the traceback with the call to Variable.__init__(). The exception was raised with the statement "self.tk = master.tk". The following error message indicates that this "master" parameter is NoneType, and thus would have no such tk attribute. Looking at the Tkinter documentation for StringVar here: http://epydoc.sourceforge.net/stdlib/Tkinter.StringVar-class.html

the master parameter is set to default to None. It looks like master should be supplied as a widget that might contain this StringVar (i.e. would it make sense to have a StringVar not associated with a widget?). I would have to say that you most definitely need to associate a StringVar object with a widget for it to have a 'tk' attribute.