Why do i get this output:
running this:
and pressing arrow-keys
Code:
Exception in Tkinter callback
Traceback (most recent call last):
File "/usr/lib/python3.7/tkinter/__init__.py", line 1705, in __call__
return self.func(*args)
File "/home/arch/python/spaceacard.py", line 10, in UpKey
Ship.sety(x+10)
UnboundLocalError: local variable 'x' referenced before assignment
Exception in Tkinter callback
Traceback (most recent call last):
File "/usr/lib/python3.7/tkinter/__init__.py", line 1705, in __call__
return self.func(*args)
File "/home/arch/python/spaceacard.py", line 14, in DownKey
Ship.sety(x-10)
UnboundLocalError: local variable 'x' referenced before assignment
Code:
#!/usr/bin/python3
import turtle
from tkinter import *
e=0
x=0
Ship=turtle.Turtle()
Ship.penup()
def UpKey(event):
Ship.sety(x+10)
x=x+10
def DownKey(event):
Ship.sety(x-10)
x=x-10
main = Tk()
while e==0:
main.bind('<Up>', UpKey)
main.bind('<Down>', DownKey)
main.mainloop()