Python的TKinter的事件处理、Event Formats(事件格式数据)

本文探讨了Python的Tkinter库中Button类型的常用操作事件,包括鼠标按键的按下、释放、按着路过及离开等。同时,介绍了事件格式数据(Event Formats),详细解析了事件中包含的组件信息如位置、类型、键盘和鼠标按键等关键数据。对于Tkinter的高效开发,文章提供了相关资源链接。

最常用的Button类型有哪些操作事件呢呢?

  1. 鼠标左、中、右键,按下;
  2. 鼠标左、中、右键,释放;
  3. 鼠标左、中、右键,按着路过;
  4. 鼠标离开;
import tkinter

window = tkinter.Tk()
window.title("GUI")

b = tkinter.Button(window, text = "Button") # this is placed in 1 0
b.pack()

#creating 3 different functions for 3 events
def left_click(event):
    tkinter.Label(window, text = "Left Click!").pack()

def left_released(event):
    tkinter.Label(window, text = "Left Released!").pack()

def left_Motion(event):
    tkinter.Label(window, text = "Left Motion!").pack()
    
def left_doubleclick(event):
    tkinter.Label(window, text = "Left Double Click!").pack()
    
def left_Motion(event):
    tkinter.Label(window, text = "Left Move!").pack()

def middle_click(event):
    tkinter.Label(window, text = "Middle Click!").pack()

def right_click(event):
    tkinter.Label(window, text = "Right Click!").pack()
    
b.bind("<Button-1>", left_click)
b.bind("<B1-Motion>", left
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值