Tkinter Scale

Tkinter Scale widget is used to implement a graphical slider to the User interface giving the user the option of picking through a range of values in python. The programmer can set the Maximum and Minimum values on the Scale.

Syntax:

The parameter, master represents the parent window, and options are used to set various attributes as key-values separated by commas. The options are described below:

Options of Tkinter Scale:

fg: Shows the color for the text.

from_: This option defines the start point of the scale

font: Shows the type of font used for this widget.

highlightcolor: Color of the text when the widget is under focus.

highlightbackground: Shows the color of the focus highlight when the scale does not have focus.

showvalue: Shows the current value of the scale displayed in a label beside it. To turn the label off, set it to 0.

activebackground: Background color when the mouse is over the scale.

orient: This option sets the Orientation of the Scale. By default is Horizontal. To displaying vertical, use Vertical.

label: This option is used to create a label within the scale widget to display the text.

tickinterval: Set’s the “tick” interval for displaying the values on the scale.

to: The Value of either integer or float shows the one end range of the scale. The to value can be either greater than or less than the from_ value.

variable: Control variables may be from class IntVar, DoubleVar, or StringVar. Within the last-mentioned case, the numerical value will be changed over to a string.

relief: This option specifies the type of border. By default is Flat, other options include RAISED and SUNKEN.

bd: This shows the size of the border around the widget. By default value is 2 pixels.

length: Shows the length of Scale widget. By default is 100 pixels.

bg: Shows the background color for the area around the widget.

sliderlength: It sets the length of the slider. By default is 30 pixels.

troughcolor: This option sets the color of the trough in the widget.

width: Shows the width of the trough in the scale. By default value is 15 pixels. 

repeatdelay: This option used to control how long button 1 has to be held down in the trough before the slider starts moving in that direction repeatedly. By default repeatdelay=300, and the units are milliseconds.

Methods of Tkinter Scale:

set ( value ): This method sets the scale’s value.

get(): This method returns the current value of the scale.

Example:
from tkinter import *

appWindow = Tk()
appWindow.title("Window Title-Tutorialsart.com")

appWindow.geometry('350x200')

Frame1 = Frame(appWindow)
Frame1.pack()

Scala = Scale(Frame1, from_ = 0, to = 10)  # default orientation is vertical
Scala.pack(padx=5, pady=5)

Scala2 = Scale(Frame1, from_ = 0, to = 10, orient=HORIZONTAL)
Scala2.pack(padx=5, pady=5)
appWindow.mainloop()
Output:
15 tkinter scale

Comments are closed.