我正在尝试为我已经实现的多个按钮添加一个悬停选项,但我想在一个类中这样做,以节省我单独为每个按钮添加选项。 我用python编写代码,并使用tkinter作为GUI。在
class GUIButtons():
def __init__(self, window):
self.window = window
self.Calculate = Button(window, command=GetUnits, text="Calculate", width = 19, background = "dark blue", fg="white")
self.Calculate.grid(row=1, column=4, sticky=NSEW)
self.ShowMethod = Button(window, command=ShowMethod, text="Show method", width = 19, background = "darkblue", fg="white")
self.ShowMethod.grid(row=1, column= 5, sticky=NSEW)
self.Submit = Button(window, command = lambda: GetCoordinate(Message), text="Submit", width = 6, height = 1, background = "dark blue", fg="white", font = 11)
self.Submit.grid(row=3, column = 3, sticky = NSEW)
self.Displacement = Button(window, text="Displacement", background = "Dark Blue", fg="white", font=11)
self.Displacement.grid(row=2, column=1, sticky= N)
不知道如何绑定鼠标悬停选项一次,它适用于我的所有按钮。在
任何帮助将不胜感激!在
见Instance and Class Bindings
还有例子
所以使用}和{}可以做到。在
bind_class
和{在
编辑:示例-当鼠标
enter/hover
任何按钮时,都将调用test()
。在在
您还可以创建自己的小部件来更改现有的小部件。在
红色按钮:
^{pr2}$或者
在
编辑:
如果你只需要改变悬停按钮的颜色,那么你就不需要绑定函数了。按钮有
activebackground=
和activeforeground=
。在见Button
编辑:它在Windows、Linux和OS X上的行为可能不同
相关问题 更多 >
编程相关推荐