Meter widget of ttkbootstrap

Ttkbootstrap Meter
A radial meter that can be used to show progress of a process or can be used as input to the process.
arcrangeArc range in degree.
arcoffsetOffset from starting position in degree, 0 position is at 3'Oclock .
amounttotalThe maximum value of the Arc
amountusedCurrent Meter value, displayed at center if showtext is True.
wedgesizeThe length of the wedge if not equal to 0 .
metersizeSize of one side of the Meter ( as a squre ).
arcrangeArc range in degree.
bootstyleStyle keyword, options are
primary, secondary, success,info,warning,danger, light, dark
metertype FULL or SEMI
meterthicknessThickness of indicator.
showtextTrue / False, Show the text.
interactiveIf True then indicator can be adjusted using Mouse
stripethicknessIf greater than 0 then striped bands with thickness is shown.
textleftAt the left of center text.
textrightAt the right of center text.
textfontFont for the center text. textfont=['Times',10,'bold']
subtextSupplemental text below center text.
subtextstyleBootstyle colour of subtext.
subtextfontFont for subtext .
stepsizeStep size of increment on Mouse interaction.
**kwargsOther keyword arguments.

Ttkbootstrap Meter Parameters

import ttkbootstrap as ttk
from ttkbootstrap.constants import *

my_w = ttk.Window()
my_w.geometry("400x220")  

b1 = ttk.Meter(
    master=my_w,
    amountused=85,  # Current value
    metersize=200,  # Size of the meter
    meterthickness=30,  # Thickness of the meter ring
    bootstyle=WARNING,  # Yellow color theme
)
b1.grid(row=1, column=1, padx=10, pady=10)

my_w.mainloop()
Ttkbootstrap Radial Meter widget to display or read Progress of a process

configure()

We can manage parameters by using configure().
b1.configure(amountused=25,interactive=True)

Displaying amountused value

Ttkbootstrap Meter amountusedvar
We will update the Meter by using mouse by keeping the parameter interactive=True and display the same value on a Button.
Watch this part.
b1.amountusedvar.get()
import ttkbootstrap as ttk  # Import ttkbootstrap for themed widgets
from ttkbootstrap.constants import *  # Import bootstrap constants for styling

my_w = ttk.Window()
my_w.geometry("400x220")  # Set window size (width x height)

# Create an interactive Meter widget
b1 = ttk.Meter(
    master=my_w,         # Parent widget
    amountused=65.0,     # Initial value (supports decimal)
    meterthickness=30,   # Thickness of the meter ring
    bootstyle=WARNING,   # Set the theme color to WARNING (yellow)
    interactive=True     # Allows user to adjust the meter value manually
)
b1.grid(row=1, column=1, padx=10, pady=10)  # Place the meter in the grid layout

# Function to update button text dynamically with decimal places
def update_button_text(*args):
    """
    This function updates the button text whenever the meter value changes.
    It formats the value to display 2 decimal places.
    """
    l2.configure(text=f"Value: {b1.amountusedvar.get():.2f}")  # Show value with 2 decimal places

# Create a Button that displays the meter value
l2 = ttk.Button(
    my_w, 
    text=f"Value: {b1.amountusedvar.get():.2f}",  # Initial text showing 2 decimal places
    bootstyle=DANGER  # Set button color to DANGER (red)
)
l2.grid(row=1, column=2, padx=10)  # Place the button in the grid layout

# Bind the meter variable to update the button text when the meter value changes
b1.amountusedvar.trace("w", update_button_text)

# Run the Tkinter event loop
my_w.mainloop()

Using bootstyle parameter

Ttkbootstrap Meter colours
Inside a for loop we can add different available bootstrap style colours by using bootstyle parameter.
Check how the textfont, subtextfont parameters are used.
import ttkbootstrap as ttk
from ttkbootstrap.constants import *

my_w = ttk.Window()
my_w.geometry("720x80")

c = 0 # Column value 

for my_style in my_w.style.colors:  # List of styles
    m1 = ttk.Meter(
        subtext=my_style, subtextfont=['Times',6,'normal'],
        textfont=['Times',6,'bold'], metersize=80,
        amountused=65, bootstyle=my_style
    )
    m1.grid(row=1, column=c, padx=5)
    c = c + 1

my_w.mainloop()

textfont, textleft, textright, subtext, subtextfont, subtextstyle

Ttkbootstrap Meter colours
b1 = ttk.Meter(
    my_w,
    amountused=65,
    meterthickness=30,
    bootstyle=INFO,
    interactive=True,
    textfont=['Times',26,'bold'],
    textright='%',
    textleft='Speed',
    subtext='Performance',
    subtextfont=['Times',10,'normal'],
    subtextstyle=SECONDARY
)

stripthickness

Ttkbootstrap Meter stripethickness with timer
We can create segments in meter, by using stripthickness to more than 0. Here is one example using one segment representing one second. We are using one 60 second Meter where the starting of the counting is triggered by click of a button. Each second one segment is added.

To trigger the function to change the value we have used one recursive timer. It takes the inputs in milliseconds and after the delay triggers the function
gap_sec=1000 #  milliseconds
my_w.after(gap_sec,my_second) 
Full code is here
import ttkbootstrap as ttk
from ttkbootstrap.constants import *

my_w = ttk.Window()
my_w.geometry("220x260")  # width and height

m1 = ttk.Meter(
    my_w,
    amounttotal=59,
    amountused=0,
    meterthickness=20,
    bootstyle=INFO,
    metersize=200,
    stripethickness=6
)
m1.grid(row=1, column=1, padx=5, pady=10)

count = 0  
gap_sec = 10 # Time delay in milliseconds

def my_second():
    global count
    if count <= 59:
        m1['amountused'] = count  # update meter value
        count = count + 1
        my_w.after(gap_sec, my_second) # time delay in milliseconds
    else:
        count = 0

b1 = ttk.Button(my_w, text='Start', command=my_second)
b1.grid(row=2, column=1)

my_w.mainloop()

Using Meter Widget in ttkbootstrap

The Meter widget in ttkbootstrap provides a visually appealing way to display progress, gauge values, or performance metrics in your Tkinter applications. It supports various styles and themes, making it a great addition to modern GUI designs.

Visit Documentation

Ttkbootstrap Meter bootstyle option using range Two Interlinked Meters Displaying number of chars entered in Text widget using Meter
ttkbootstrap

Monitor System Performance using ttkbootstrap Meter and psutil
Countdown Timer using ttkbootstrap Meter
Typing speed test by setting Countdown Timer

Subscribe to our YouTube Channel here


Subscribe

* indicates required
Subscribe to plus2net

    plus2net.com







    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