我目前正在创建一个国际象棋游戏的python和我想能够移动我的键盘当我点击这个棋子
root = tk.Tk()
canvas = tk.Canvas(root, width=1000, height=800)
canvas.pack()
img = tk.PhotoImage(file="pixil-frame-0.png")
image = canvas.create_image(100,0,image=img,anchor=tk.NW)
def move(event):
if event.char == "a":
canvas.move(image, -100, 0)
if event.char == "d":
canvas.move(image,100,0)
if event.char == "w":
canvas.move(image,0,-100)
if event.char =="s":
canvas.move(image,0,100)
root.bind("<Key>", move)
root.mainloop()
如果我不先点击它,我预计不能移动它,但现在我可以移动它而不必点击它
目前没有回答
相关问题 更多 >
编程相关推荐