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)
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



Simple message area


Simple labeled pushbutton widget


Container for attaching and arranging other widget objects

Toplevel, Tk

Top-level windows managed ...

Get Python Pocket Reference, Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.