So I'd like to add all the tk.Button(and entry) objects in an entire program to a list. (so that I can change the colours of every button though iterate and config)
I'm creating a bunch of tkinter frames like this:
class AppClass(tk.Tk):
def __init__(self, *args, **kwargs):
# Initialising Tkinter
tk.Tk.__init__(self, *args, **kwargs)
tk.Tk.wm_title(self, 'test-program')
tk.Tk.geometry(self, '800x480')
container = tk.Frame(self)
container.pack(fill='both', expand=True)
container.grid_rowconfigure(0, weight=1)
container.grid_columnconfigure(0, weight=1)
self.background_theme = '2'
self.background_theme_to_be_written_to_file = '2'
self.frames = {}
for F in (HomePage,
SecondName,
ThirdName):
frame = F(container, self)
self.frames[F] = frame
frame.grid(row=0, column=0, sticky="nsew")
frame.configure(background=background_page)
self.show_frame(HomePage)
...
app = AppClass()
app.mainloop()
app = None
exit()
Ideas? I know .winfo_children()
can select all the objects in a page - can we select all the objects in the program?
**
at the moment I'm trying to make something like this work - oddly it's only changing one button on the screen (There are 4):
parent.list_of_objects_in_parent = tk.Button.winfo_children(parent)
print(parent.list_of_objects_in_parent)
for entry in parent.list_of_objects_in_parent:
entry.config(bg="pink")
**quick update:
I kind of have a partial solution:
self.bind("<<ShowFrame>>", self.on_show_frame)
...
def on_show_frame(self, event):
self.list_of_objects_in_parent = tk.Button.winfo_children(self)
print(self.list_of_objects_in_parent)
for entry in self.list_of_objects_in_parent:
if type(entry) == type(self.button_to_go_to_home_page):
entry.config(bg="pink")
print("working")