Python Forum
Thread Rating:
  • 2 Vote(s) - 3 Average
  • 1
  • 2
  • 3
  • 4
  • 5
tkinter themes
#1
This isnt mine, i just thought it was nice to display the available themes

import random
import tkinter
from tkinter import ttk
from tkinter import messagebox

class App(object):

    def __init__(self):
        self.root = tkinter.Tk()
        self.style = ttk.Style()
        available_themes = self.style.theme_names()
        random_theme = random.choice(available_themes)
        self.style.theme_use(random_theme)
        self.root.title(random_theme)

        frm = ttk.Frame(self.root)
        frm.pack(expand=True, fill='both')
    # create a Combobox with themes to choose from
        self.combo = ttk.Combobox(frm, values=available_themes)
        self.combo.pack(padx=32, pady=8)
    # make the Enter key change the style
        self.combo.bind('<Return>', self.change_style)
    # make a Button to change the style
        button = ttk.Button(frm, text='OK')
        button['command'] = self.change_style
        button.pack(pady=8)

    def change_style(self, event=None):
        """set the Style to the content of the Combobox"""
        content = self.combo.get()
        try:
            self.style.theme_use(content)
        except tkinter.TclError as err:
            messagebox.showerror('Error', err)
        else:
            self.root.title(content)

app = App()

Attached Files

Thumbnail(s)
   
Recommended Tutorials:
Reply


Messages In This Thread
tkinter themes - by metulburr - Sep-20-2017, 11:00 PM
RE: tkinter themes - by Larz60+ - Sep-20-2017, 11:07 PM
RE: tkinter themes - by metulburr - Sep-21-2017, 12:05 AM
RE: tkinter themes - by loombago - Mar-28-2019, 08:48 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020