I want to be able to manipulate an integer that will be displayed in real-time in the Tk window.
I tried:
xp = StringVar()
Label(master, textvariable=xp).pack()
xp.set(0)
and then later, I tried:
xp.set(xp+1)
But it failed badly on that line, with the message:
Exception in Tkinter callback
File "/usr/lib/.../Tkinter.py", line 1413, in __call__
return self.func(*args)
File "rpg.py", line 26, in fight
xp.set(xp+1)
NameError: global name 'xp' is not defined
I want to be able to increment the “xp” value, and it show up in real-time in the window. I also want to be able to manipulate “xp” as an integer, with multiplication and exponents and the such.
So if you can point out what I am doing incorrectly then I would be glad.
Looks to me like the scope of the
xpvariable in the first snippet does not include the second snippet. This means that they’re really different variables (that happen to have a very similar name) and so the second snippet is being run without the handle to theStringVaraccessible, which isn’t going to work.