Python Tkinter call a dictionary with a StringVar? Python Tkinter call a dictionary with a StringVar? tkinter tkinter

Python Tkinter call a dictionary with a StringVar?


Just as you had to call set method of StringVar object, you also need to call get to retrieve the str data.

print weightsy[acadw.get()]

The dictionary doesn't know to convert your object into a string so it attempts to get the value associated with acadw. You get a TypeError rather than a KeyError since StringVar objects happen to be unhashable.