slightlynybbled / tk_tools

Python tkinter tools, Python3.7+
MIT License
101 stars 25 forks source link

Is there any way to change the settings for the gauge without destroying and calling it again? #48

Closed toxicfeet closed 2 years ago

toxicfeet commented 3 years ago

I am trying to dynamically change the gauge parameters for min/max value and update the value for the gauge but cannot figure out how to do this. Is it possible with this module?

from tkinter import *
import tk_tools
from time import sleep

root = Tk()

gauge = tk_tools.Gauge(root, 
                       min_value=20.0,
                       max_value=65.0,
                       divisions=int((65-20)/5),
                       red_low=25,
                       yellow_low=35,
                       yellow=55,
                       red=60,
                      )

gauge.set_value(10)
gauge.pack()
i=20

loop = True
while loop:
    try:     
        gauge.update()

        if i < 25:
            gauge.pack_forget()
            gauge = tk_tools.Gauge(root, 
                       min_value=i,
                       max_value=65.0,
                       divisions=int((65-20)/5),
                       red_low=25,
                       yellow_low=35,
                       yellow=55,
                       red=60,
                      )
            gauge.pack()

        gauge.set_value(i)
        gauge.pack()
        i+= 1
        if i>25:
            i = 20
        sleep(0.1)  
    except KeyboardInterrupt:
        root.quit()
        loop = False    

''

slightlynybbled commented 3 years ago

Not a use case that I anticipated at the time of writing. In your use case, I would save a local instance of the settings as a dict and, when those values changed (new_settings != settings), destroy the gauge and re-initialize.