ttkbootstrap : A supercharged theme extension for tkinter.

ttkbootstrap is a modern-themed extension of Tkinter’s ttk (Themed Tkinter) module that enhances GUI applications with Bootstrap-inspired styling. It provides a set of pre-designed themes, new widget styles, and additional features to make Tkinter-based applications look more visually appealing and modern.
# Install the ttkbootstrap library using pip 
pip install ttkbootstrap
Display Buttons with ttkbootstrap style
ttkboostrap sample window with a button
# Import required modules
import ttkbootstrap as ttk
from ttkbootstrap.constants import *

# Create main window
my_w = ttk.Window()
my_w.geometry("400x150") # Set window width and height

# Create success button
b1 = ttk.Button(my_w, text="Button Success", bootstyle=SUCCESS)
b1.grid(row=0, column=0, padx=30, pady=30)

# Create primary button
b1 = ttk.Button(my_w, text="Button Primary", bootstyle=PRIMARY)
b1.grid(row=0, column=1, padx=30, pady=30)

# Run main event loop
my_w.mainloop()

Style & Theme

We use style for applying individual attributes to widgets, where as Theme is for set of attributes applied to the total or all the Apps.

Styles

List of styles available with ttkboostrap are PRIMARY, SECONDARY, SUCCESS, INFO, WARNING, DANGER, LIGHT, DARK
ttkboostrap sample window with a button
All ttkbootstrap styles are applied using the bootstyle parameter. Check the above code were two styles SUCCESS and PRIMARY are used. We can use all the avilable styles and apply to buttons.
import ttkbootstrap as ttk
from ttkbootstrap.constants import *

my_w = ttk.Window()
my_w.geometry("520x200")
c=0
for my_style in my_w.style.colors: # List of styles 
    b = ttk.Button(my_w, text=my_style, bootstyle=my_style)
    b.grid(row=1, column=c, padx=2, pady=20)

    b = ttk.Button(my_w, text=my_style, bootstyle=(my_style, OUTLINE))
    b.grid(row=2, column=c, padx=2, pady=20)
    c = c + 1
my_w.mainloop()
Ttkbootstrap installation and list of available styles and themes using buttons and other widgets

Themes

There are nearly 18 themes available in ttkboostrap.
Here is the code to list all themes or apply any perticular theme or to get the current theme of the application.
import ttkbootstrap as ttk
from ttkbootstrap.constants import *

my_w = ttk.Window()
my_w.geometry("800x800")

my_themes=my_w.style.theme_names() # Lit of available themes 
my_w.style.theme_use('darkly') # Use or set this theme 
print(my_w.style.theme_use()) # name of currently used theme

my_w.mainloop()

Updating default font

Use these lines after declaring the root window.
from tkinter.font import nametofont
default_font = nametofont("TkDefaultFont")
default_font.configure(family="Times",size=14,weight='bold')
Ttkbootstrap applying available themes to widgets by selecting radiobuttons
We will combine style and them to create one application where a set of radio buttons will be used for selection of a particular theme. User can change the selection to apply different themes to all the available widget.
Here each widget type is created by using all the styles available.
ttkboostrap themes
Full code is here
import ttkbootstrap as ttk
from ttkbootstrap.constants import *

my_w = ttk.Window()
my_w.geometry("950x500")
#
my_themes = my_w.style.theme_names()  # List of available themes
my_str = ttk.StringVar(value=my_w.style.theme_use())  # default selection of theme
r, c = 0, 0  # row=0 and column =0
for values in my_themes:  # List of available themes
    b = ttk.Radiobutton(
        my_w, text=values, variable=my_str, value=values, command=lambda: my_upd()
    )  # Radio buttons with themes as values 
    b.grid(row=r, column=c, padx=5, pady=20)
    c = c + 1  # increase column by 1
    if c > 8:  # One line complete so change the row and column values
        r, c = r + 1, 0
c, r = 0, r + 1
for my_style in my_w.style.colors:  # List of styles
    b = ttk.Button(my_w, text=my_style, bootstyle=my_style)
    b.grid(row=r, column=c, padx=1, pady=20)
    b = ttk.Button(my_w, text=my_style, bootstyle=(my_style, OUTLINE))
    b.grid(row=r + 1, column=c, padx=1, pady=20)
    m1 = ttk.Meter(
        subtextstyle=my_style, metersize=100, amountused=65, bootstyle=my_style
    )
    m1.grid(row=r + 2, column=c)
    fg = ttk.Floodgauge(value=75, bootstyle=my_style)
    fg.grid(row=r + 3, column=c, padx=1, pady=20)
    # de=ttk.DateEntry(bootstyle=color)
    # de.grid(row=r+4,column=c,padx=1,pady=20)
    c = c + 1

def my_upd():
    my_w.style.theme_use(my_str.get())

my_w.mainloop()

Explore the Latest ttkbootstrap Widgets

Here is a list of essential widgets, including new additions like Floodgauge, Meter, and Toast, which bring progress indicators, notifications, and more dynamic UI elements to our applications. Click on the links to explore each widget in detail.


CheckbuttonsVersatile toggle buttons that can be styled as switches or checkboxes. Ideal for user preferences, settings menus, and multi-option selections.
ColorChooserDialogInteractive color selection dialog for choosing colors easily. Useful for design applications, theme customization, and graphic tools.
TableviewDisplays tabular data with sorting and styling options. Great for managing datasets, logs, and spreadsheet-like interfaces.
MeterModern radial progress indicator with customizable styles. Perfect for dashboards, task completion tracking, and fitness apps.
FloodgaugeA sleek horizontal progress indicator. Useful for showing download progress, form completion status, or time-sensitive tasks.
DateEntryDropdown calendar for easy date selection. Ideal for booking systems, forms, and event schedulers.
ToolTipDisplays helpful text in a popup on mouse hover. Useful for explaining form fields, buttons, or complex UI elements.
ToastNon-intrusive pop-up message alerts. Ideal for showing notifications, updates, and user feedback.

Advantages of ttkbootstrap Over Traditional Tkinter

ttkbootstrap is an enhanced version of Tkinter that brings a modern and stylish look to GUI applications. It eliminates the need for manual styling and provides Bootstrap-like themes and widgets, making it a preferred choice for developers who want a sleek UI with minimal effort.

🌟 Key Advantages of ttkbootstrap Over Traditional Tkinter

  • Predefined Modern Themes 🎨
    • Comes with built-in themes (e.g., dark mode, light mode, and colorful themes).
    • Eliminates the need for manual styling with colors and fonts.
  • Better Styling with Bootstrap-like Classes ✨
    • Uses classes like btn-primary, btn-success, btn-danger, etc., similar to Bootstrap.
    • Provides a more consistent and professional look for UI elements.
  • Enhanced Widget Appearance πŸ–₯
    • Improves the look of buttons, labels, entry fields, and other widgets.
    • Widgets automatically adapt to the selected theme.
  • Easy Theming and Customization 🎭
    • Allows users to switch themes dynamically.
    • Provides more polished UI designs with minimal effort.
  • Backwards Compatibility with Tkinter πŸ”„
    • Works seamlessly with existing Tkinter code.
    • You can gradually enhance a Tkinter app by integrating ttkbootstrap without rewriting everything.

βœ… Why Choose ttkbootstrap? πŸš€

If you want a modern UI with **minimal coding effort**, ttkbootstrap is the perfect choice. It enhances Tkinter's functionality while maintaining compatibility, making it ideal for both new and existing projects.


Explore ttkbootstrap Documentation

Discover the full capabilities of ttkbootstrap, including widgets, themes, and styling options to enhance your Tkinter applications.

Visit Documentation


Subscribe to our YouTube Channel here


Subscribe

* indicates required
Subscribe to plus2net

    plus2net.com



    27-12-2022

    While running the ttkbootstrap code , i am getting the colors the first time. When i am again running the code, i am not getting the colors for SUCCESS, PRIMARY and so on.

    08-01-2023

    Just copy the above code and try. How you are running the code again ? Are you sure you are using the loop second time ?

    It should work.

    17-10-2023

    pourquoi select_item ne fonctionne pas dans ttkbootstrap python?




    Python Video Tutorials
    Python SQLite Video Tutorials
    Python MySQL Video Tutorials
    Python Tkinter Video Tutorials
    We use cookies to improve your browsing experience. . Learn more
    HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
    ©2000-2024 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer