close

Modern Tkinter

Modern Tkinter ebook

Want TkDocs to go? If you've found the material on this site useful, please consider buying this book, which is based on the Python material in the tutorial.


Mark Roseman

p.s. your purchase helps me improve this site... thank you!

 

Only $10 for e-book. pick your format:

Paperback PDF Kindle Apple Books B&N Nook Kobo

(Slightly more for paperback. Also available on other e-book platforms.)

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:ttk::entry .e -textvariable name
Ruby:$name = TkVariable.new ( initialValue );
e = Tk::Tile::Entry.new(parent) {textvariable $name}
Perl:my $e = parent->new_ttk__entry(-textvariable => $name);
Python:name = StringVar()
e = ttk.Entry(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).