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()
Various possible options in Python Tkinter Scale:
|activebackground||This option is used to set background color of widget under focus.|
|bg||This option helps us to set the normal background colour of the widget.|
|bd||This option is used to set the size of border around the widget.|
|command||This option helps us to mention a function to every time when RadioButton will change its state.|
|cursor||This option helps us to set the style of cursor like an arrow, dot etc|
|font||This option is used to set font type in the widget.|
|fg||This option helps us to set the normal foreground colour of the widget.|
|from_||This option id used to start point of scale’s range.|
|highlightbackground||This option is used to set the color of the focus highlight when the widget is not having the focus.|
|highlightcolor||This option is used to set highlight colour shown to the widget under focus.|
|label||This option is used to show a label with scale.|
|length||This option is used to set length of the scale widget.By default 100px.|
|orient||This option is used to set the orientation of Scale.|
|relief||This helps us to set the style of the border by which is default Flat.|
|sliderlength||This option is used to set length of scale slider which is normally 30px you can change it.|
|state||This option is used to set state or Scale. By default it is NORMAL. You can also set it DISABLE.|
|tickinterval||This option is used to set a tick interval in scale.|
|to||This option is used ending point of scale’s range.|
|troughcolor||This option is used to set the colour of the trough.|
|variable||This option is used to set a variable in Scale.|
|width||This 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.
|get()||This method returns the current value of scale.|
|set ( value )||This method helps us to set the value of scale.|