back next

The Tkinter Scale Widget

The Scale widget allows the user to select a numerical value by moving a “slider” knob along a scale. You can control the minimum and maximum values, as well as the resolution.

When to use the Scale Widget

You can use the Scale widget instead of an Entry widget, when you want the user to input a bounded numerical value.

Patterns #

To create a scale with a specified range, use the from and to options. Note that to pass the from option as a keyword argument, you need to add a trailing underscore (from is a reserved keyword in Python).

from Tkinter import *

master = Tk()

w = Scale(master, from_=0, to=100)
w.pack()

w = Scale(master, from_=0, to=200, orient=HORIZONTAL)
w.pack()

mainloop()

To query the widget, call the get method:

w = Scale(master, from_=0, to=100)
w.pack()

print w.get()

The default resolution is 1, which causes the widget to round all values to the nearest integer value. You can use the resolution option to specify another resolution; use -1 to disable rounding.

w = Scale(from_=0, to=100, resolution=0.1)

Reference #

Scale(master=None, **options) (class) [#]

A scale (slider).

master
Parent widget.
**options
Widget options. See the description of the config method for a list of available options.

config(**options) [#]

Modifies one or more widget options. If no options are given, the method returns a dictionary containing all current option values.

**options
Widget options.
activebackground=
Default value is system specific. (the database name is activeBackground, the class is Foreground)
background=
Default value is system specific. (background/Background)
bg=
Same as background.
bigincrement=
Default value is 0. (bigIncrement/BigIncrement)
borderwidth=
Default value is 2. (borderWidth/BorderWidth)
bd=
Same as borderwidth.
command=
No default value. (command/Command)
cursor=
No default value. (cursor/Cursor)
digits=
Default value is 0. (digits/Digits)
font=
Default value is system specific. (font/Font)
foreground=
Default value is system specific. (foreground/Foreground)
fg=
Same as foreground.
from=
Default value is 0. (from/From)
highlightbackground=
Default value is system specific. (highlightBackground/HighlightBackground)
highlightcolor=
Default value is system specific. (highlightColor/HighlightColor)
highlightthickness=
Default value is 2. (highlightThickness/HighlightThickness)
label=
No default value. (label/Label)
length=
Default value is 100. (length/Length)
orient=
Default value is VERTICAL. (orient/Orient)
relief=
Default value is FLAT. (relief/Relief)
repeatdelay=
Default value is 300. (repeatDelay/RepeatDelay)
repeatinterval=
Default value is 100. (repeatInterval/RepeatInterval)
resolution=
Default value is 1. (resolution/Resolution)
showvalue=
Default value is 1. (showValue/ShowValue)
sliderlength=
Default value is 30. (sliderLength/SliderLength)
sliderrelief=
Default value is RAISED. (sliderRelief/SliderRelief)
state=
Default value is NORMAL. (state/State)
takefocus=
No default value. (takeFocus/TakeFocus)
tickinterval=
Default value is 0. (tickInterval/TickInterval)
to=
Default value is 100. (to/To)
troughcolor=
Default value is system specific. (troughColor/Background)
variable=
No default value. (variable/Variable)
width=
Default value is 15. (width/Width)

coords(value=None) [#]

Gets the screen coordinate corresponding to the given scale value.

value
A scale value. If omitted, this method uses the current setting.
Returns:
The corresponding screen coordinate, as a 2-tuple.

get() [#]

Gets the current scale value. Tkinter returns an integer if possible, otherwise a floating point value.

Returns:
The current value, as an integer or floating point value. To make sure you have a floating point value, use float(scale.get()).

identify(x, y) [#]

Checks if an active part of the scale is at the given screen location.

x
The horisontal screen coordinate.
y
The vertical screen coordinate.
Returns:
A string identifying what part of the scale is at the given location. This can be “slider”, “through1” (above or to the left of the slider), “through2” (below or to the right), or an empty string for any other part of the widget.

set(value) [#]

Sets the scale value.

value
The new scale value.

 

A Django site. rendered by a django application. hosted by webfaction.