This method uses classes
import tkinter as tk root = tk.Tk() class Button: def __init__(self, win, text, color): self.btn = tk.Button(win, text=text, command=self.change_color) self.btn.pack() self.color = color def change_color(self): self.btn.config(bg=self.color) btn1 = Button(root, 'one', '#00ffff') btn2 = Button(root, 'two', '#0000ff') root.mainloop()
Recommended Tutorials: