萌新求助关于tkinter
代码如下,事件绑定鼠标悬停到组件上,文本和背景色会发生改变。现在想要鼠标离开后,组件恢复原样,该如何设置事件和方法啊from tkinter import *
tool = Tk()
def callback(event):
event.widget['bg']='blue'
event.widget['fg']='white'
l1 = Label(tool,text='左键点我')
l1.bind('<Motion>',callback)
l1.pack()
mainloop()
用 <Leave> 捕捉即可,参考代码:
from tkinter import *
tool = Tk()
tool.geometry('50x50')
def callback(event):
event.widget['bg'] = 'blue'
event.widget['fg'] = 'white'
def leave(event):
event.widget['bg'] = 'SystemButtonFace'
event.widget['fg'] = 'SystemButtonText'
l1 = Label(tool, text='左键点我')
l1.bind('<Motion>', callback)
l1.bind('<Leave>', leave)
l1.pack()
mainloop()
页:
[1]