“Ubah warna tombol saat melayang” Kode Jawaban

Ubah warna tombol saat melayang

import tkinter as tk

def on_enter(e):
    myButton['background'] = 'green'

def on_leave(e):
    myButton['background'] = 'SystemButtonFace'

root = tk.Tk()
myButton = tk.Button(root,text="Click Me")
myButton.grid()


myButton.bind("<Enter>", on_enter)
myButton.bind("<Leave>", on_leave)

root.mainloop()
Tired Tuatara

Ubah warna tombol saat melayang

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("<Enter>", self.on_enter)
        self.bind("<Leave>", 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()
Tired Tuatara

Jawaban yang mirip dengan “Ubah warna tombol saat melayang”

Pertanyaan yang mirip dengan “Ubah warna tombol saat melayang”

Lebih banyak jawaban terkait untuk “Ubah warna tombol saat melayang” di Python

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya