How to change the theme of my tkinter application in Python? How to change the theme of my tkinter application in Python? tkinter tkinter

How to change the theme of my tkinter application in Python?


Below is an modified example using ttk widgets based on your code:

from tkinter import *import tkinter.ttk as ttkimport randomwindow = Tk()window.title("Running Python Script") # Create windowwindow.geometry('550x300') # geo of the windows=ttk.Style()s.configure("TButton", foreground="red", background="blue")list_themes = s.theme_names()current_theme = s.theme_use()#s.theme_use('classic')print(list_themes)def run():    if dd_owner.get() == "Spain":        print("spain")    # choose a theme randomly    theme = random.choice(list_themes)    print("theme:", theme)    s.theme_use(theme)# These are the option menusowner = ("Spain", "France", "Germany")dd_owner = StringVar(window)dd_owner.set(owner[0]) # the first value#w = OptionMenu(window, dd_owner, *owner)# use ttk.Combobox instead of OptionMenuw = ttk.Combobox(window, textvariable=dd_owner, values=owner)w.grid(row=0, column=1)#The run button#run_button = Button(window, text="Run application {}".format(dd_owner.get()), bg="blue", fg="white",command=run)# use ttk.Buttonrun_button = ttk.Button(window, text="Run application {}".format(dd_owner.get()), command=run)run_button.grid(column=0, row=2)# These are the titlesl1 = ttk.Label(window, text='Select Owner', width=15)l1.grid(row=0, column=0)mainloop()

When you click the button, it will change the theme randomly.