O'Reilly logo

Python GUI Programming with Tkinter by Alan D. Moore

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

A range-limited Spinbox widget

A number entry seems like it shouldn't be too complicated to deal with, but there are a number of subtleties to work through to make it bulletproof. In addition to limiting the field to valid number values, you'll want to enforce the from, to, and increment arguments as the minimum, maximum, and precision of the input, respectively.

The algorithm needs to implement the following rules:

  • Deletion is always allowed
  • Digits are always allowed
  • If from is less than 0, a minus is allowed as the first character
  • If increment has a decimal component, one dot is allowed
  • If the proposed value is greater than the to value, ignore the keystroke
  • If the proposed value requires more precision than increment, ignore the keystroke ...

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