O'Reilly logo

Tkinter GUI Programming by Example by David Love

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

The Spinbox widget

The Spinbox widget is a widget that allows the programmer to set specified values, either as a single tuple of choices or two keyword arguments that specify the beginning and end of a range.

Since we want to force the font size to be an integer, and we can assume that nobody will want a font size under 5 or over 99, we can use these things to form our Spinbox:

self.size_input = tk.Spinbox(self, from_=5, to=99, value=self.master.font_size)

We create a Spinbox widget, passing the parent widget as normal.

The from_ keyword argument is used to specify the minimum selectable value. The argument requires a trailing underscore because the word from is a keyword in Python. Likewise, the to argument specifies the maximum value. ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required