【发布时间】:2014-04-11 09:56:31
【问题描述】:
标题说明了一切。我可以调用 Tkinter 中有什么东西可以让我监控特定的密钥版本并将其链接到一个函数吗?我想用它来结束我用来移动我的项目的计时器。代码如下:
from Tkinter import *
master = Tk()
master.wm_title("Ball movement")
width = 1000
height = 600
circle = [width / 2, height / 2, width / 2 + 50, height / 2 + 50]
canvas = Canvas(master, width = width, height = height, bg = "White")
canvas.pack()
canvas.create_oval(circle, tag = "ball", fill = "Red")
while True:
canvas.update()
def move_left(key):
#This is where my timer will go for movement
canvas.move("ball", -10, 0)
canvas.update()
def move_right(key):
#This is where my other timer will go
canvas.move("ball", 10, 0)
canvas.update()
frame = Frame(master, width=100, height=100)
frame.bind("<Right>", move_right)
frame.bind("<Left>", move_left)
frame.focus_set()
frame.pack()
mainloop()
【问题讨论】: