- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How can I set the default value of my Tkinter Scale widget slider to 100?
Tkinter Scale Widgets are used to provide the visual representation of data items where we can modify or change the value of data items. In order to change the state of data or select multiple data in the field, we can use the Scale widget.
The Scale Widget can be created by initializing a Scale(parent, from_, to, orient, options) constructor.
However, sometimes we need to set the default value of the Tkinter Scale widget, which can be set by using the set(numeric_value) method.
Example
In this example, we will create a scale widget that sets a default value for the slider.
#Import the required Libraries from tkinter import * from tkinter import ttk #Import the required Libraries from tkinter import * from tkinter import ttk #Create an instance of tkinter frame win = Tk() #Set the geometry of tkinter frame win.geometry("750x250") #Define a function to reset the slider def reset_slider(): horizontal.set(100) #Initialize a Horizontal Scale Widget horizontal=Scale(win, from_=0, to=200, orient= HORIZONTAL) #Set the Default Value of Scale Widget horizontal.set(100) horizontal.pack() #Create a button to reset the slider ttk.Button(win, text= "Reset", command= reset_slider).pack(pady=15) win.mainloop()
Output
Now, run the above code to display the Slider that has some default value.
In the given output, when we modify the slider value, we can reset it by clicking the "Reset" Button.