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
#2
The problem is that they don't look the same on all operating systems, and some don't work at all in MS windows.
This is one of the reasons why I am now using wxpython phoenix.
So far, they seem consistent and very easy to use.

Though not as complete as Qt, I'm really impressed with this release.
wx formbuilder (https://github.com/wxFormBuilder/wxFormBuilder)
continues to evolve (last change 3 days ago), and may someday be as good as qt designer.
Reply
#3
I know they dont look the same on all OS's. I thought it was different themes based on python version and OS's as well.
Recommended Tutorials:
Reply
#4
Hi, this code doesn't work properly on Python 3.x unless you add self.root.mainloop() to App class __init__ function.
Reply


Forum Jump:

User Panel Messages

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