Creating a Scale
Assigning a Callback
Orientation
Minimum and Maximum Values
Displayed Versus Stored Value
Adding a Label
Displaying Value Increments
Changing the Size of the Scale
Options You'll Probably Never Need
Configuring a Scale
Getting the Value of a Scale
Setting the Value of a Scale
Determining Coordinates
Identifying Parts of a Scale
A Scale widget looks similar to a Scrollbar but doesn't scroll anything other than itself. What it does is keep track of a number. When you change the position of the button in the Scale, the numeric value associated with the Scale changes. Some things you can do with a Scale widget are:
Create a widget from which a user can select a number between 1 and 100.
Create three Scales, each representing a value in an RGB (red, green, blue) number.
Create four sliders, each representing a portion of an IP address. Each Scale can go from 0 to 255, and it would probably be smart to start them at 255. Use a Label widget to show the completed IP address, periods and all.
Create a temperature Scale that starts at -50 and goes to 130 degrees.
Show the amount of rainfall so far this year. The Scale can be marked to show every five inches.
The Scale widget can be placed horizontally or vertically, depending on where you have the most room in your application window. Figure 10-1 shows a scale widget.
As with other widgets, to create a Scale, use a parent widget and pass options to the Scale to change its configuration:
$parent->Scale( [ option => value ] )->pack;
Use one of the geometry managers discussed in Chapter 2, "Geometry Management" to place it on the screen (such as pack, as shown in the preceding code).
Most of the options associated with the Scale widget are standard options used with all other widgets. All the possible options are in the following list. A discussion of special options that have slightly different meanings for the Scale and options that are specific to the Scale widget follows the list.
Copyright © 2002 O'Reilly & Associates. All rights reserved.