Meter bootstyle based on Range

Ttkbootstrap meter range

Triggering changes in meter value

We kept the option interactive=True, so when the value of the meter i.e amountusedvar is changed by mouse, it triggers the function my_upd() by using the trace method.
m1.amountusedvar.trace("w", my_upd) # On change of amountusedvar
More about trace()

Bootstyle parameter to manage colour based on amountused value of a Ttkbootstrap Meter widget #7

Function my_upd()

This function is called when the value or amountusedvar option of the meter is changed. Inside this function we will keep if elif condition checks to set the option bootstyle to different colors. There are 8 different colors are already avilable here is the list.

PRIMARY, SECONDARY, SUCCESS, INFO, WARNING, DANGER, LIGHT, DARK
def my_upd(*args):
    if m1["amountused"] <= 30:
        m1["bootstyle"] = SUCCESS
    elif m1["amountused"] <= 60:
        m1["bootstyle"] = PRIMARY
    elif m1["amountused"] <= 90:
        m1["bootstyle"] = WARNING
    else:
        m1["bootstyle"] = DANGER

import ttkbootstrap as ttk
from ttkbootstrap.constants import *

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

def my_upd(*args):
    if m1["amountused"] <= 30:
        m1["bootstyle"] = SUCCESS
    elif m1["amountused"] <= 60:
        m1["bootstyle"] = PRIMARY
    elif m1["amountused"] <= 90:
        m1["bootstyle"] = WARNING
    else:
        m1["bootstyle"] = DANGER

m1 = ttk.Meter(
    my_w,
    amountused=10,
    metersize=300,
    meterthickness=40,
    interactive=True,
    metertype=SEMI,
    bootstyle=SUCCESS,
)
m1.grid(row=0, column=0, padx=60, pady=10)

m1.amountusedvar.trace("w", my_upd) # On change of amountusedvar

my_w.mainloop()
Two Interlinked Meters
Ttkbootstrap Meter Displaying number of chars entered in Text widget using Meter
ttkbootstrap
Subscribe to our YouTube Channel here


Subscribe

* indicates required
Subscribe to plus2net

    plus2net.com



    Post your comments , suggestion , error , requirements etc here





    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