pythontkintersliderpositiontkinter-scale

How to make the slider of a Tkinter Scale widget start in certain place?


I am using the tkinter Scale widget and I have a scale set up from 0 to 200. When I open it up, I want the slider to be set at 100 (halfway on the trough) not 0. Is there a way for this to be done?


Solution

  • You can use the tkinter.Scale.set method to set the scale to whatever value.

    Below is a simple script to demonstrate:

    from tkinter import Tk, Scale
    
    root = Tk()
    
    w = Scale(root, from_=0, to=200)
    w.pack()
    w.set(100)  # Set the initial value to 100
    
    root.mainloop()
    

    Example:

    enter image description here