首页 > 编程语言 > 详细

Python button bind event

时间:2017-08-21 11:20:35      阅读:512      评论:0      收藏:0      [点我收藏+]
# <Button-1>:鼠标左击事件
# <Button-2>:鼠标中击事件
# <Button-3>:鼠标右击事件
# <Double-Button-1>:双击事件
# <Triple-Button-1>:三击事件

from tkinter import *
tk = Tk()
canvas = Canvas(width=500,height=500)
canvas.pack()


#canvas.create_polygon(0,0,250,250,fill = ‘red‘)

def echo_event(evt):
    #打印键盘事件
    if evt.type == "2":
        print("键盘:%s" % evt.keysym)
    #打印鼠标操作
    if evt.type == "4":
        print("鼠标: %s" % evt.num)
    #
    print(evt.type)

#键盘事件
canvas.bind_all("<KeyPress>",echo_event)
#如果绑定指定的键盘,则"<Key>" 或者"<KeyPress>"都可以,具体到指定键的话后面加入下划线和指定的键就好了,如:绑定小写字母t和Left键
canvas.bind_all("<KeyPress-t>",echo_event)
canvas.bind_all("<KeyPress-Left>",echo_event)
#鼠标事件
canvas.bind_all("<Double-Button-1>",echo_event)
canvas.bind_all("<Button-1>",echo_event)
canvas.bind_all("<Button-2>",echo_event)
canvas.bind_all("<Button-3>",echo_event)

Python button bind event

原文:http://www.cnblogs.com/njuptlwh/p/7403233.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!