python编程-14:tkinter绘制接收事件的图形

python编程-14:tkinter绘制接收事件的图形

源码:

from tkinter import *
 
def main():   
    tk = Tk()
    canvas = Canvas(tk, width = 400, height = 400)
    canvas.pack()
 
    def moverectangle(event):
        if event.keysym == "Up":
            canvas.move(1,0,-5)
        elif event.keysym == "Down":
            canvas.move(1,0,5)
        elif event.keysym == "Left":
            canvas.move(1,-5,0)
        elif event.keysym == "Right":
            canvas.move(1,5,0)
         
    canvas.create_rectangle(180,180,220,220,fill="red")
    canvas.bind_all("",moverectangle)
    canvas.bind_all("",moverectangle)
    canvas.bind_all("",moverectangle)
    canvas.bind_all("",moverectangle)
 
if __name__ == '__main__':
    main()

原文地址: http://www.icourse163.org/learn/BIT-268001?tid=1002001005#/learn/content?type=detail&id=1002613050&cid=1002856149

python编程-14:tkinter绘制接收事件的图形

上一篇:汇编程序:显示时间中响应键盘中断


下一篇:《C#多线程编程实战(原书第2版)》——3.6 在线程池中使用等待事件处理器及超时