Changing Theme of a Tkinter GUI

Hello everyone, In this tutorial, we will learn about how to change the theme of Tkinter GUI. We create a GUI application using Tkinter but we don’t know how to change those boring traditional widgets with something that looks more attractive to the user. We do not get external theme support so we will be using a python library named ttkthemes which has included many themes for our application. This Library supports python version 2.7 or more.

Let’s start by installing ttkthemes in our Python environment.

Installing ttkthemes

We can install ttkthemes with the command below.

pip install ttkthemes

We can also install via Git using

python3 -m pip install git+https://github.com/RedFantom/ttkthemes

Before start Coding, we recommend that you get used to the basics of Tkinter. Refer to these tutorials.

Introduction to Tkinter module in Python

Tkinter pack() , grid() Method In Python

All set guys, Let us change that default theme.

Change Theme with ttkthemes – Tkinter GUI

We assume that you have prior knowledge of basic imports while making a Tkinter GUI and will describe the new things that we will be doing in our code.

import tkinter as tk
import tkinter.ttk as ttk 
from ttkthemes import ThemedStyle

We have imported ThemedStyle from ttkthemes which supports the external themes provided by this package and sets those themes to the Tk instance of our GUI.

 

app = tk.Tk()
app.geometry("200x400")
app.title("Changing Themes")
# Setting Theme
style = ThemedStyle(app)
style.set_theme("scidgrey")

In the code above we have created a Tk instance as ‘app’ and set the theme as ‘scidgrey’ which is provided by the ThemeStyle package.

Let us create some widgets using both tk(Default_Themed) and ttk(External_Themed) and see the difference between them.

# Button Widgets
Def_Btn = tk.Button(app,text='Default Button')
Def_Btn.pack()
Themed_Btn = ttk.Button(app,text='Themed button')
Themed_Btn.pack()

# Scrollbar Widgets
Def_Scrollbar = tk.Scrollbar(app)
Def_Scrollbar.pack(side='right',fill='y')
Themed_Scrollbar = ttk.Scrollbar(app,orient='horizontal')
Themed_Scrollbar.pack(side='top',fill='x')

# Entry Widgets
Def_Entry = tk.Entry(app)
Def_Entry.pack()
Themed_Entry = ttk.Entry(app)
Themed_Entry.pack()

app.mainloop()
We want you to try to run the program and see the output.

List of themes in ttkthemes

  • Aquativo
  • Arc
  • Clearlooks
  • Equilux
  • Keramic
  • Plastik
  • Radiance
  • Scid themes
  • Smog

There are many more themes in this Library, look at them here

We hope you really enjoy this tutorial and if you have any doubt, feel free to leave a comment below.

Learn more with us:

Python program for login page using Tkinter package

Create a registration form in python using Tkinter package

Leave a Reply

Your email address will not be published. Required fields are marked *