In this tutorial, we will learn about Python Tkinter Scale. Tkinter Scale widget is used to create a graphical slider on the screen. This widget allows user to move scale and to select a particular value on the scale.
Syntax of the Python Tkinter Scale:
w = Scale (master, options)
- master: This represents the parent window.
- options: Here is the list of most commonly used options for this widget.
Example of the Tkinter Scale:
# importing tkinter lib
from tkinter import *
value = "Value is = " + str(svar.get())
label.config(text = value)
mainWindow = Tk()
svar = DoubleVar()
scale = Scale(mainWindow, variable = svar )
button = Button(mainWindow, text="Show Selected Value", command=show)
label = Label(mainWindow,pady=10)
Various possible options in Python Tkinter Scale:
|This option is used to set background color of widget under focus.
|This option helps us to set the normal background colour of the widget.
|This option is used to set the size of border around the widget.
|This option helps us to mention a function to every time when RadioButton will change its state.
|This option helps us to set the style of cursor like an arrow, dot etc
|This option is used to set font type in the widget.
|This option helps us to set the normal foreground colour of the widget.
|This option id used to start point of scale’s range.
|This option is used to set the color of the focus highlight when the widget is not having the focus.
|This option is used to set highlight colour shown to the widget under focus.
|This option is used to show a label with scale.
|This option is used to set length of the scale widget.By default 100px.
|This option is used to set the orientation of Scale.
|This helps us to set the style of the border by which is default Flat.
|This option is used to set length of scale slider which is normally 30px you can change it.
|This option is used to set state or Scale. By default it is NORMAL. You can also set it DISABLE.
|This option is used to set a tick interval in scale.
|This option is used ending point of scale’s range.
|This option is used to set the colour of the trough.
|This option is used to set a variable in Scale.
|This helps us to set the width of the widget.
Tkinter Scale Methods:
After learning about various available options in Python Tkinter Scale. Its time to check out some available methods for Tkinter Scale widget.
|This method returns the current value of scale.
|set ( value )
|This method helps us to set the value of scale.