O'Reilly logo

Tkinter GUI Application Development Blueprints - Second Edition by Bhaskar Chaudhary

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

Key validation mode demo

Let's assume that we have a form that asks for a username. We want users to input only alphabetical or space characters in the name. Thus, a number of special characters should not be allowed, as shown in the following screenshot of the widget:

This is clearly a case for the key validation mode because we want to check whether an entry is valid after every keypress. The percent substitution that we need to check is %S because it yields the text string being inserted or deleted in the Entry widget. Therefore, the code that validates the Entry widget is as follows (see the 10.05_key_validation.py code):

import tkinter ...

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