Python 2.X, and a module package in Python 3.0) is a portable graphical
user interface (GUI) construction library shipped with Python as a
standard library module.
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. Other portable GUI options for Python such
as wxPython and PyQT are
third-party extensions with richer widget sets but generally more
complex coding requirements.
tkinter scripts, widgets are customizable classes (e.g.,
Frame), options are keyword arguments (e.g.,
text="press"), and composition refers to object embedding, not
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()
Table 1-21 lists the primary widget classes in the
tkinter module. These are true Python
classes that can 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()). In addition ...