Home Contact

TkDocs

Information you need to build high-quality Tk user interfaces.

close

Modern Tkinter ebook If you've found the material on this site useful, please consider purchasing this e-book (only $10), which is based on the Python material in the tutorial. Doing so helps me maintain and update this site. Thank you very much!


 
 
@markroseman
mark@markroseman.com

 

Kindle Buy now for your Kindle
Kindle apps are also available for most smartphones, tablets, and desktops. Payment and download handled by Amazon's Kindle Store.

 

PDF Buy the DRM-free PDF
Downloads handled by SendOwl.com. Payment handled via PayPal
(click "Don't have a PayPal account" to use a credit card).

The widget roundup provides you with a quick and easy reference to the most important features and options for each Tk widget.

Entry

Widget Essentials

When to use: Anywhere the user needs to provide a single-line string, not confined to a known choice, such as a name, address, password, etc. Use a separate label widget to identify the entry if needed.
Tcl usage: ttk::entry .e -textvariable name
Ruby usage: $name = TkVariable.new ( initialValue );
Tk::Tile::Entry.new(parent) {textvariable $name}
Reference: (at www.tcl.tk)

Common Options

textvariable A variable linked to the entry; when the variable is changed, the entry will be updated, while when the user changes the entry, the variable will be updated.
show Show the given character instead of each letter in the actual entry; e.g. set to "*" for a password field.
width The number of characters wide the entry widget is onscreen; this does not constrain the number of characters the entry can actually hold (see validation).

How do I...

Get the current value? Look at the linked variable, or use the "get" method.
Change the current value? Change the linked variable.
You can also use the "delete first ?last?" and "insert first text" methods. Both "first" and "last" are 0-based indices indicating character position (use "end" for last), while "text" is the new text to insert.
Disable the entry? Use the "state disabled" method.
You can reenable this with "state !disabled".
Check with "instate disabled" (returns 1 if disabled, else 0).
Validate the entry? TODO.