Chapter 10. The Scale Widget

A scale widget is a strange little widget. It's similar to a scrollbar because it is long and skinny with a button in the middle of it, but it doesn't scroll anything other than itself. It does keep track of something though—a number. When you change the position of the button in the scale, the value associated with the scale changes. Here are some things you can do with a scale widget:

  • 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 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.

Get Learning 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.