[Tkinter] Resetting scale value back to 0 after the slider loses focus - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: GUI (https://python-forum.io/forum-10.html) +--- Thread: [Tkinter] Resetting scale value back to 0 after the slider loses focus (/thread-2315.html) |
Resetting scale value back to 0 after the slider loses focus - lwhistler - Mar-07-2017 I am using the scale widget in Tkinter and after I scale the value from 0 I would like the value to go back to 0 once the slider loses focus. (This would be the CameraPan variable) Example: I slide the scale to 45 and when I release the mouse the scale jumps back to 0. My question is how can I do that? Thanks for your help. #! /usr/bin/env python from Tkinter import * master = Tk() def camera_pan(camera_pan_value): print(camera_pan_value) CameraPan=0 CameraPan180 = Scale(master, from_=-90, to=90,tickinterval=15,label="Camera Pan (left right)",resolution=1,orient=HORIZONTAL,length=350,width=25,command=camera_pan) CameraPan180.set(CameraPan) CameraPan180.pack() mainloop() RE: Resetting scale value back to 0 after the slider loses focus - Larz60+ - Mar-07-2017 create two variables cpmin = -90 cmmax = 90 use: #! /usr/bin/env python from Tkinter import * master = Tk() cpmin = -90 cpmax = 90 def camera_pan(camera_pan_value): print(camera_pan_value) if(camera_pan_value == max): camera_pan180.set(cpmin) CameraPan=cpmin CameraPan180 = Scale(master, from_=cpmin, to=cpmax, tickinterval=15, label="Camera Pan (left right)", resolution=1, orient=HORIZONTAL, length=350, width=25, command=camera_pan) CameraPan180.set(cpmin) CameraPan180.pack() mainloop() RE: Resetting scale value back to 0 after the slider loses focus - lwhistler - Mar-07-2017 That doesn't work. I want the scale to reset to 0 after I move the slider. Example: I slide the scale to 45 and when I release the mouse the scale automatically resets to 0 - without me having to drag it back to 0. RE: Resetting scale value back to 0 after the slider loses focus - Larz60+ - Mar-07-2017 so change the -90 to 0 ? |