Python Tkinter Scale

By | April 20, 2020

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 Python Tkinter Scale:

# importing tkinter lib
from tkinter import *  

def show():
    value = "Value is = " + str(svar.get())
    label.config(text = value)
    
mainWindow = Tk()  

mainWindow.geometry("320x180")

svar = DoubleVar()
scale = Scale(mainWindow, variable = svar )
scale.pack(anchor=CENTER)

button = Button(mainWindow, text="Show Selected Value", command=show)
button.pack(anchor=CENTER)

label = Label(mainWindow,pady=10)
label.pack()

mainWindow.mainloop() 

Output:

Python Tkinter Scale

Various possible options in Python Tkinter Scale:

OptionDescription
activebackgroundThis option is used to set background color of widget under focus.
bgThis option helps us to set the normal background colour of the widget.
bdThis option is used to set the size of border around the widget.
commandThis option helps us to mention a function to every time when RadioButton will change its state.
cursorThis option helps us to set the style of cursor like an arrow, dot etc
fontThis option is used to set font type in the widget.
fgThis option helps us to set the normal foreground colour of the widget.
from_This option id used to start point of scale’s range.
highlightbackgroundThis option is used to set the color of the focus highlight when the widget is not having the focus.
highlightcolorThis option is used to set highlight colour shown to the widget under focus.
labelThis option is used to show a label with scale.
lengthThis option is used to set length of the scale widget.By default 100px.
orientThis option is used to set the orientation of Scale.
reliefThis helps us to set the style of the border by which is default Flat.
sliderlengthThis option is used to set length of scale slider which is normally 30px you can change it.
stateThis option is used to set state or Scale. By default it is NORMAL. You can also set it DISABLE.
tickintervalThis option is used to set a tick interval in scale.
toThis option is used ending point of scale’s range.
troughcolorThis option is used to set the colour of the trough.
variableThis option is used to set a variable in Scale.
widthThis helps us to set the width of the widget.

Python Tkinter Scale Functions:

There are various Python Tkinter Scale functions available. Which makes it so easy to use entry widget in our application these functions are as follow.

FunctionDescription
get()This method returns the current value of scale.
set ( value )This method helps us to set the value of scale.