We kept the option interactive=True, so when the value of any meter i.e amountusedvar is changed by mouse, it triggers the respective function by using the trace method.
m1.amountusedvar.trace("w", my_upd1) # Trigger on change of value
m2.amountusedvar.trace("w", my_upd2)
Two interlined Ttkbootstrap Meter widgets to change synchronously when any amountused is changed #8
Functions to update
Two functions are used to update the amountused parameter. These functions are called when the value or amountusedvar option of the meter is changed. Inside this function we are updating the other Meter' amountused parameter.
def my_upd1(*args): # When Meter1 is updated
m2["amountused"] = m1["amountused"] # m2 is updated
def my_upd2(*args): # When Meter2 is updated
m1["amountused"] = m2["amountused"] # m1 is updated
import ttkbootstrap as ttk
from ttkbootstrap.constants import *
my_w = ttk.Window()
my_w.geometry("500x250")
def my_upd1(*args): # When Meter1 is updated
m2["amountused"] = m1["amountused"]
def my_upd2(*args): # When Meter2 is updated
m1["amountused"] = m2["amountused"]
m1 = ttk.Meter(
my_w,
amountused=25,
metersize=225,
meterthickness=30,
interactive=True,
)
m1.grid(row=0, column=0, padx=10, pady=10)
m2 = ttk.Meter(
my_w,
amountused=25,
metersize=225,
meterthickness=30,
interactive=True,
bootstyle=SUCCESS
)
m2.grid(row=0, column=1, padx=10, pady=10)
m1.amountusedvar.trace("w", my_upd1) # Trigger on change of value
m2.amountusedvar.trace("w", my_upd2)
my_w.mainloop()