Что я понимаю, что tk
является экземпляром Tk()
. Затем вы можете использовать tk.winfo_children()
, чтобы получить всех детей tk
, и использовать isinstance()
, чтобы проверить, является ли ребенок Label
:
def monitor_changes():
registry = ConnectRegistry(None, HKEY_CURRENT_USER)
key = OpenKey(registry, r'SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize')
mode = QueryValueEx(key, "AppsUseLightTheme")
tk.config(bg="#f0f0f0" if mode[0] else "black")
# go through all the children of tk
for widget in tk.winfo_children():
# check whether widget is instance of Label
if isinstance(widget, Label):
widget.config(bg="#f0f0f0" if mode[0] else "black")
tk.after(100,monitor_changes)