Skip to Content
Python in a Nutshell
book

Python in a Nutshell

by Alex Martelli
March 2003
Intermediate to advanced
656 pages
39h 30m
English
O'Reilly Media, Inc.
Content preview from Python in a Nutshell

Widget Fundamentals

The Tkinter module supplies many kinds of widgets, and most of them have several things in common. All widgets are instances of classes that inherit from class Widget. Class Widget itself is abstract; that is, you never instantiate Widget itself. You only instantiate concrete subclasses corresponding to specific kinds of widgets. Class Widget’s functionality is common to all the widgets you instantiate.

To instantiate any kind of widget, call the widget’s class. The first argument is the parent window of the widget, also known as the widget’s master. If you omit this positional argument, the widget’s master is the application’s main window. All other arguments are in named form, option = value. You can also set or change options on an existing widget w by calling w .config( option = value ). You can get an option of w by calling w. cget('option'), which returns the option’s value. Each widget w is a mapping, so you can also get an option as w ['option'] and set or change it with w ['option']= value.

Common Widget Options

Many widgets accept some common options. Some options affect a widget’s colors, others affect lengths (normally in pixels), and there are various other kinds. This section details the most commonly used options.

Color options

Tkinter represents colors with strings. The string can be a color name, such as 'red' or 'orange', or it may be of the form '# RRGGBB', where each of R, G, and B is a hexadecimal digit, to represent a color by the values ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Python in a Nutshell, 3rd Edition

Python in a Nutshell, 3rd Edition

Alex Martelli, Anna Ravenscroft, Steve Holden
Python in a Nutshell, 4th Edition

Python in a Nutshell, 4th Edition

Alex Martelli, Anna Martelli Ravenscroft, Steve Holden, Paul McGuire
Data Wrangling with Python

Data Wrangling with Python

Jacqueline Kazil, Katharine Jarmul

Publisher Resources

ISBN: 0596001886Supplemental ContentCatalog PageErrata