Oct-19-2020, 04:59 AM
I think you kind of over thought it, the class isn't needed
here's an example:
Quote: Is there a way of detecting which button is clicked when they have been instantiated this way.Yes by indexing a list and using functool -> partial.
here's an example:
import tkinter as tk from functools import partial root= tk.Tk() def do_something(index): button_list[index].config(bg='green',fg='white') frame= tk.Frame(bg='gray60', width= 1280, height= 720) frame.pack() button_list= [] for x in range(0,3): text_='Button {0}'.format(x) button_list.append(tk.Button(frame,text=text_,compound='center', font=('comicsans',16,'italic'), command= partial(do_something,x), relief= tk.FLAT)) button_list[-1].place(relx=x/4, rely=x/4, relwidth=0.18, relheight=0.18) root.mainloop()