当鼠标悬停在按钮上时,如何更改图像? 我需要当您将鼠标悬停在按钮1或2上时,图片会发生变化:
Photo1 = (file='Image\ProgrammingButton')
Photo2 = (file='Image\DesignButton')
But1 = (root, image=Photo1)
But2 = (root, image=Photo2)
悬停
Photo1 = (file='Image\ActiveProgrammingButton')
Photo2 = (file='Image\ActiveDesignButton')
Tkinter有“enter”和“leave”事件,您必须将它们绑定到某个函数,并且可以使用
config
方法更改图像下面是一个演示:
如果您希望许多按钮都具有这种效果。我建议您创建自己的按钮,继承
Button
类这里有一个例子
Thx至@furas建议。这是更新的类
如何使用: 只需在img1和img2参数中指定图像路径
以下是一个例子:
相关问题 更多 >
编程相关推荐