I am working on my final project, where we are supposed to create a tank game and right now we are just making the frame of program. I want to move the tank with keys across the tkinter area, however i have tried many things and still i am getting many different errors. Also, when the program atleast started, the tank wouldn´t move at all. Would appreciate some help. Here is my code :
master=Tk()
master.title("WOT")
plocha=Canvas(master,width=800,height=500)
plocha.pack()
x = None
y = None
t1 = None
t2 = None
t3 = None
t4 = None
def tank():
t1=plocha.create_rectangle(int(x)+50,int(y)+375,int(x)+100,int(y)+425)
t2=plocha.create_rectangle(int(x)+45,int(y)+370,int(x)+50,int(y)+430)
t3=plocha.create_rectangle(int(x)+100,int(y)+370,int(x)+105,int(y)+430)
t4=plocha.create_rectangle(int(x)+72.5,int(y)+350,int(x)+77.5,int(y)+400)
def pozicia():
x=input("Zadaj pozíciu tanku(x):")
y=input("Zadaj pozíciu tanku(y):")
tank()
def vlavo(event):
x=-10
y=0
plocha.move(t1,x,y)
plocha.move(t2,x,y)
plocha.move(t3,x,y)
plocha.move(t4,x,y)
plocha.update()
def vpravo(event):
x=10
y=0
plocha.move(t1,x,y)
plocha.move(t2,x,y)
plocha.move(t3,x,y)
plocha.move(t4,x,y)
plocha.update()
def hore(event):
x=0
y=-40
plocha.move(t1,x,y)
plocha.move(t2,x,y)
plocha.move(t3,x,y)
plocha.move(t4,x,y)
plocha.update()
def dole(event):
x=0
y=10
plocha.move(t1,x,y)
plocha.move(t2,x,y)
plocha.move(t3,x,y)
plocha.move(t4,x,y)
plocha.update()
plocha.bind("<w>",hore)
plocha.bind("<a>",dole)
plocha.bind("<s>",vlavo)
plocha.bind("<d>",vpravo)
pozicia()
plocha.mainloop()
tk.Frame()and make everything class variables. fe: look at this link to see how to do this...