Next / Previous / Contents / Shipman's homepage

Abstract

Describes the Tkinter widget set for constructing graphical user interfaces (GUIs) in the Python programming language. Includes coverage of the ttk themed widgets.

This publication is available in Web form and also as a PDF document. Please forward any comments to john@nmt.edu.

This work is licensed under a Creative Commons BY-NC Creative Commons Attribution-NonCommercial 3.0 Unported License.

Table of Contents

1. A cross-platform graphical user interface builder for Python
2. A minimal application
3. Definitions
4. Layout management
4.1. The .grid() method
4.2. Other grid management methods
4.3. Configuring column and row sizes
4.4. Making the root window resizeable
5. Standard attributes
5.1. Dimensions
5.2. The coordinate system
5.3. Colors
5.4. Type fonts
5.5. Anchors
5.6. Relief styles
5.7. Bitmaps
5.8. Cursors
5.9. Images
5.10. Geometry strings
5.11. Window names
5.12. Cap and join styles
5.13. Dash patterns
5.14. Matching stipple patterns
6. Exception handling
7. The Button widget
8. The Canvas widget
8.1. Canvas coordinates
8.2. The Canvas display list
8.3. Canvas object IDs
8.4. Canvas tags
8.5. Canvas tagOrId arguments
8.6. Methods on Canvas widgets
8.7. Canvas arc objects
8.8. Canvas bitmap objects
8.9. Canvas image objects
8.10. Canvas line objects
8.11. Canvas oval objects
8.12. Canvas polygon objects
8.13. Canvas rectangle objects
8.14. Canvas text objects
8.15. Canvas window objects
9. The Checkbutton widget
10. The Entry widget
10.1. Scrolling an Entry widget
10.2. Adding validation to an Entry widget
11. The Frame widget
12. The Label widget
13. The LabelFrame widget
14. The Listbox widget
14.1. Scrolling a Listbox widget
15. The Menu widget
15.1. Menu item creation (coption) options
15.2. Top-level menus
16. The Menubutton widget
17. The Message widget
18. The OptionMenu widget
19. The PanedWindow widget
19.1. PanedWindow child configuration options
20. The Radiobutton widget
21. The Scale widget
22. The Scrollbar widget
22.1. The Scrollbar command callback
22.2. Connecting a Scrollbar to another widget
23. The Spinbox widget
24. The Text widget
24.1. Text widget indices
24.2. Text widget marks
24.3. Text widget images
24.4. Text widget windows
24.5. Text widget tags
24.6. Setting tabs in a Text widget
24.7. The Text widget undo/redo stack
24.8. Methods on Text widgets
25. Toplevel: Top-level window methods
26. Universal widget methods
27. Standardizing appearance
27.1. How to name a widget class
27.2. How to name a widget instance
27.3. Resource specification lines
27.4. Rules for resource matching
28. ttk: Themed widgets
28.1. Importing ttk
28.2. The ttk widget set
29. ttk.Button
30. ttk.Checkbutton
31. ttk.Combobox
32. ttk.Entry
33. ttk.Frame
34. ttk.Label
35. ttk.LabelFrame
36. ttk.Menubutton
37. ttk.Notebook
37.1. Virtual events for the ttk.Notebook widget
38. ttk.PanedWindow
39. ttk.Progressbar
40. ttk.Radiobutton
41. ttk.Scale
42. ttk.Scrollbar
43. ttk.Separator
44. ttk.Sizegrip
45. ttk.Treeview
45.1. Virtual events for the ttk.Treeview widget
46. Methods common to all ttk widgets
46.1. Specifying widget states in ttk
47. Customizing and creating ttk themes and styles
48. Finding and using ttk themes
49. Using and customizing ttk styles
50. The ttk element layer
50.1. ttk layouts: Structuring a style
50.2. ttk style maps: dynamic appearance changes
51. Connecting your application logic to the widgets
52. Control variables: the values behind the widgets
53. Focus: routing keyboard input
53.1. Focus in ttk widgets
54. Events
54.1. Levels of binding
54.2. Event sequences
54.3. Event types
54.4. Event modifiers
54.5. Key names
54.6. Writing your handler: The Event class
54.7. The extra arguments trick
54.8. Virtual events
55. Pop-up dialogs
55.1. The tkMessageBox dialogs module
55.2. The tkFileDialog module
55.3. The tkColorChooser module

1. A cross-platform graphical user interface builder for Python

Tkinter is a GUI (graphical user interface) widget set for Python. This document was written for Python 2.7 and Tkinter 8.5 running in the X Window system under Linux. Your version may vary.

Pertinent references:

We'll start by looking at the visible part of Tkinter: creating the widgets and arranging them on the screen. Later we will talk about how to connect the face—the “front panel”—of the application to the logic behind it.