-1

hello guys i am working with a code that i cant understand:

current_value = tk.DoubleVar()

def get_current_value(): 
    return '{: .2f}'.format(current_value.get())

def brightness_changed(event):
    pct.set_brightness(get_current_value())

brightness = ttk.Scale(RHS,from_=0,to=100,orient='horizontal',
            command=brightness_changed,variable=current_value)

well, the last line is ok i made it myself, but the other is unknow for me, could you pleases simply tell me what is going on here?

Payam
  • 57
  • 7
  • Does this answer your question? [When to use Variable classes? (BooleanVar, DoubleVar, IntVar, StringVar)](https://stackoverflow.com/questions/47334885/when-to-use-variable-classes-booleanvar-doublevar-intvar-stringvar) – JNevill Sep 23 '22 at 18:35

1 Answers1

0

DoubleVar() is used for storing floats. In the code it is used by the Scale widget; each time you slide the scale the widget sets the current_value variable.

The widget also points to an event listener (using command) - a callback function that does something each time the slider moves or settles. As you can see this sets the brightness of pct - whatever that is - using the value in current_value. The function get_current_value seems a bit uneccesary, as the event parameter in brightness_changed contains the value of the slider.

Olav
  • 547
  • 1
  • 5
  • 17