Tkinter GUI Module and Tools
Tkinter is a portable graphical user interface (GUI) construction library shipped with Python as a standard library module. Tkinter provides an object-based interface to the open source Tk library and implements native look and feel for Python-coded GUIs on Windows, X-Windows, and Mac OS. It is portable, simple to use, well-documented, widely used, mature, and well-supported.
Tkinter Example
In Tkinter scripts, widgets are customizable
classes (e.g., Button
, Frame
),
options are keyword arguments (e.g.,
text="press"
), and
composition is object embedding, not pathnames
(e.g., Label(Top,...)
).
from Tkinter import * # widgets, constants def msg( ): # callback handler print 'hello stdout...' top = Frame( ) # make a container top.pack( ) Label(top, text="Hello world").pack(side=TOP) widget = Button(top, text="press", command=msg) widget.pack(side=BOTTOM) top.mainloop( )
Tkinter Core Widgets
Table 1-20 lists the primary widget classes in the
Tkinter module. These are true Python classes that may be subclassed
and embedded in other objects. To create a screen device, make an
instance of the corresponding class, configure it, and arrange it
with one of the geometry manager interface methods (e.g.,
Button(text='hello').pack( )
).
Table 1-20. Tkinter core widget classes
Widget class |
Description |
---|---|
|
Simple message area |
|
Simple labeled pushbutton widget |
|
Container for attaching and arranging other widget objects |
|
Top-level windows managed ... |
Get Python Pocket Reference, Second Edition 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.