Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Slider GUI help
#5
You should only have one "forever loop" in a tkinter program and that is the mainloop(). The while loop in StartC() locks up you GUI because it is preventing mainloop() from running. If you want to update the tank level to follow the slider you need to periodically call a function that gets the slider value, calculates a new tank level, and updates the level display (Svalue). This function should run for a very short time so it does not interfere with mainloop().

You could specify a command for the slider and always update Svalue whenever the slider is changed. This will update Svalue to be the same as Slider.get(), but it would be more realistic if you had the tank "fill" to the requested level. To fill the tank you need to periodically call a function that "drives" the tank level (float(Svalue['text']) toward the tank level command (Slider['value']).

An easy way to periodically call a function in tkinter is use "after". Here's a small change to your code that will update the Svalue every second after you press the Start button.
def StartC():
    Svalue['text'] = str(Slider.get())
    root.after(1000, StartC)
How could you change this function to ramp Svalue toward Slider.get() instead of taking one big step?
Reply


Messages In This Thread
Slider GUI help - by thass23 - Dec-02-2020, 04:04 PM
RE: Slider GUI help - by Axel_Erfurt - Dec-02-2020, 04:18 PM
RE: Slider GUI help - by thass23 - Dec-02-2020, 04:29 PM
RE: Slider GUI help - by Axel_Erfurt - Dec-02-2020, 04:53 PM
RE: Slider GUI help - by deanhystad - Dec-02-2020, 06:29 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020