
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_add("write", my_upd) # On change of amountusedvar
More about trace_add()
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_add("write", my_upd) # On change of amountusedvar
my_w.mainloop()
Two Interlinked Meters Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.