5.2. The Entry Widget
Until now, the only input we know how to get from the user is a mouseclick on a button widget (Button, Checkbutton, or Radiobutton), which is handled via the -command option. Getting input from a mouseclick is useful, but it's also limiting. The entry widget will let the user type in text that can then be used in any way by the application. Here are a few examples of where you might use an entry widget:
In a database form that requires one entry per field (e.g., Name, Last name, Address)
In a software registration window that requires a serial number
In a login window that requires a username and password
In a configuration window to get the name of a printer
In an Open File window that requires the path and name of a file
Normally, we don't care what users type in an entry widget until they are done typing, and any processing will happen "after the fact" when a user clicks some sort of Go button. You could get fancy and process each character as it's typed by setting up a complicated bind—but it is probably more trouble than it is worth.
The user can type anything into an entry widget. It is up to the programmer to decide if the text entered is valid or not. When preparing to use the information from an entry, we should do some error checking. If we want an integer and get some alphabetic characters, we should issue a warning or error message to the user.
An ...
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.