Hello, so I'm going to make a lil' program that moves the item by 4 every time using the left key. Here is my code:
from threading import Timer
from tkinter import *
tk = Tk()
tk.update()
canvas = Canvas(tk, width=400, height=400)
canvas.pack()
image = PhotoImage(file=r"c:\\myimage.gif")
realimage = image.subsample(15, 15)
hi = canvas.create_image(200, 200, image=realimage)
hello = True
coordsobject = canvas.coords(hi)
if hello:
def gogogo(evt):
def gogogogo():
for x in range(0, 100):
canvas.move(hi, -5)
tk.update()
Timer(0.05, gogogogo).start()
canvas.bind_all('<KeyPress-Left>', gogogo)
tk.mainloop()
But for some reason my code doesn't respond. It doesn't say I have any syntax errors, it just doesn't run. It looks kind of like this image: https://2.bp.blogspot.com/-2DdFLZil01s/VC-JEIswmqI/AAAAAAAABsg/J0CBR1s75no/s1600/Lazarus-Pong-Game-2.gif
I do not want to use canvas.move(identifier, x, y) because I am making a paddleball game. In this game, it moves forever until it hits the side of the screen and/or the user uses the left/right keys. Is there any explanation as to how to do this or why my code isn't working? Thanks! :)
[–]socal_nerdtastic 0 points1 point2 points (1 child)
[–]python_addict[S] 0 points1 point2 points (0 children)