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.

To specify the default value we can supply a value argument. Again this will be stored in our TextEditor class as the font_size attribute, so we pass this over to the value argument.

This finishes off the two pieces of information that we need to get from our user, so we just need a way to save this information permanently.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset