Python button bind event

# <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)

转载于:https://www.cnblogs.com/njuptlwh/p/7403233.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值