I'm working on a custom button for a list, and want to make it change color when the mouse hovers above the button. See the following code for how I'm trying to do it:
import tkinter as tk
from tkinter import *
class list_button:
def __init__(self, container, text, font_size):
self.list_button = tk.Button(container, text=text, font = ("helvatica", (0 + font_size)), relief = "flat")
self.list_button.pack()
self.list_button.bind('<Enter>', self.enter_func(self))
self.list_button.bind('<Leave>', self.leave_func(self))
def enter_func(self, key):
print("Enter")
self.list_button.configure(bg = "grey")
def leave_func(self, key):
print("Leave")
self.list_button.configure(bg = "white")
root = tk.Tk()
for i in range(10):
list_button(root, i, 15)
root.mainloop()
What seems to happen is that the code calls the function once and then unbinds the function. What am I doing wrong here?