Python Forum
[Tkinter] Resetting scale value back to 0 after the slider loses focus
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] Resetting scale value back to 0 after the slider loses focus
#1
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()
Reply
#2
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()
Reply
#3
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.
Reply
#4
so change the -90 to 0 ?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  neeed to activate a custom tk slider janeik 1 770 Oct-09-2023, 09:29 AM
Last Post: deanhystad
  [Tkinter] Open tkinter colorchooser at toplevel (so I can select/focus on either window) tabreturn 4 1,830 Jul-06-2022, 01:03 PM
Last Post: deanhystad
  How to instantly update the plot by getting values from a Scale widget? OLE 20 6,040 May-18-2022, 02:35 AM
Last Post: OLE
  How to move in entries using the arrow keys by applying the bind and focus? pymn 4 4,576 Apr-06-2022, 04:29 AM
Last Post: pymn
  tkinter slider question Nick_tkinter 1 2,433 Feb-22-2021, 01:31 PM
Last Post: deanhystad
  How to disable focus on Frame in Tkinter? szafranji 1 2,967 May-13-2020, 10:45 PM
Last Post: DT2000
  QComboBox doesn't display selection as long as it has not lost the focus Meaulnes 3 3,145 May-07-2020, 03:42 PM
Last Post: Meaulnes
  Tkinter focus catlessness 5 5,718 Apr-03-2020, 05:24 AM
Last Post: joe_momma
  Help on drawing a shape and slider mnh001 12 5,380 Aug-22-2019, 11:21 PM
Last Post: mnh001
  [Tkinter] Scale at the Top Friend 5 2,789 Jul-20-2019, 05:02 PM
Last Post: Yoriz

Forum Jump:

User Panel Messages

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