📌  相关文章
📜  在悬停的 tkinter 上更改按钮的颜色 - Python 代码示例

📅  最后修改于: 2022-03-11 14:47:21.949000             🧑  作者: Mango

代码示例2
import tkinter as tk

class HoverButton(tk.Button):
    def __init__(self, master, **kw):
        tk.Button.__init__(self,master=master,**kw)
        self.defaultBackground = self["background"]
        self.bind("", self.on_enter)
        self.bind("", self.on_leave)

    def on_enter(self, e):
        self['background'] = self['activebackground']

    def on_leave(self, e):
        self['background'] = self.defaultBackground

root = tk.Tk()

classButton = HoverButton(root,text="Classy Button", activebackground='green')
classButton.grid()

root.mainloop()