ttkbootstrap

A supercharged theme extension for tkinter.
pip install ttkboostrap
Show buttons with bootstrap stylesheet
ttkboostrap sample window with a button
import ttkbootstrap as ttk
from ttkbootstrap.constants import *

my_w = ttk.Window()
my_w.geometry("400x150") # width and height of the window 

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

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

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()
CheckbutonsCheckbuttons as Buttons and toggle switches.
ColorChooserDialogColour selection dialog box.
TableviewShowing Tabular data,
MeterRadial meter that can be used to show progress.
FloodgaugeA progress indicator of any process.
DateEntrySelect Date from Calendar.
ToolTipShowing help text in Popup window when mouse is hovering over the widget
toastPopup window for temporary alerts or messages.

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