Chapter 10. The Scale Widget

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.

Scale widget

Figure 10-1. Scale widget

Get Mastering Perl/Tk now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.