Python and Tkinter Programming
John E. Grayson
  • January 2000
  • ISBN 9781884777813
  • 688 pages

Packed with well-explained examples that teach good Python habits.

Guido van Rossum, Inventor of Python

If you are interested in Python and Tkinter, you have probably noticed that although there is some good contributed documentation on the Web, there is not enough to get Tkinter applications up and running. Python and Tkinter Programming is the answer. It is designed for readers who are familiar with Python and who need to develop applications with Graphical User Interfaces (GUIs).

Python and Tkinter Programming presents the elements of typical Python and Tkinter applications in a straight-forward fashion. Sample code illustrates each element. Complete applications that go far beyond the fill-the-form class of graphical user interfaces are presented; here you will find examples of complex controls, drawn interfaces and photorealistic panels. The code can readily be used as templates for new applications. Extensions to Python (such as ODBC) are examined as well.

About the book

Tkinter is fully documented. To date, this level of documentation has not been available to Tkinter programmers, who have been required to read the code or interpret Tcl/Tk man pages to fully understand component usage.

Python and Tkinter Programming will be useful in both Windows and Unix environments, and the example code is portable between the two environments.

Translation rights for Python and Tkinter Programming have been granted for China, Japan, and Korea. If you are interested in learning where to buy this book in a language other than English, please inquire at your local bookseller.

Table of Contents detailed table of contents


special thanks

about the reader

about the author


about the cover

author online

Part 1 Basic concepts

1. Python

1.1. Introduction to Python programming and a feature review

1.1.1. Why Python?

1.1.2. Where can Python be used?

1.2. Key data types: lists, tuples and dictionaries

1.2.1. Lists

1.2.2. Tuples

1.2.3. Dictionaries

1.3. Classes

1.3.1. How do classes describe objects?

1.3.2. Defining classes

1.3.3. Neat Python trick #10

1.3.4. Initializing an instance

1.3.5. Methods

1.3.6. Private and public variables and methods

1.3.7. Inheritance

1.3.8. Multiple inheritance

1.3.9. Mixin classes

2. Tkinter

2.1. The Tkinter module

2.1.1. What is Tkinter?

2.1.2. What about performance?

2.1.3. How do I use Tkinter?

2.1.4. Tkinter features

2.2. Mapping Tcl/Tk to Tkinter

2.3. Win32 and Unix GUIs

2.4. Tkinter class hierarchy

2.5. Tkinter widget appearance

3. Building an application

3.1. Calculator example: key features

3.2. Calculator example: source code

3.3. Examining the application structure

3.4. Extending the application

Part 2 Displays

4. Tkinter widgets

4.1. Tkinter widget tour

4.1.1. Toplevel

4.1.2. Frame

4.1.3. Label

4.1.4. Button

4.1.5. Entry

4.1.6. Radiobutton

4.1.7. Checkbutton

4.1.8. Menu

4.1.9. Message

4.1.10. Text

4.1.11. Canvas

4.1.12. Scrollbar

4.1.13. Listbox

4.1.14. Scale

4.2. Fonts and colors

4.2.1. Font descriptors

4.2.2. X Window System font descriptors

4.2.3. Colors

4.2.4. Setting application-wide default fonts and colors

4.3. Pmw Megawidget tour

4.3.1. AboutDialog

4.3.2. Balloon

4.3.3. ButtonBox

4.3.4. ComboBox

4.3.5. ComboBoxDialog

4.3.6. Counter

4.3.7. CounterDialog

4.3.8. Dialog

4.3.9. EntryField

4.3.10. Group

4.3.11. LabeledWidget

4.3.12. MenuBar

4.3.13. MessageBar

4.3.14. MessageDialog

4.3.15. NoteBookR

4.3.16. NoteBookS

4.3.17. NoteBook

4.3.18. OptionMenu

4.3.19. PanedWidget

4.3.20. PromptDialog

4.3.21. RadioSelect

4.3.22. ScrolledCanvas

4.3.23. ScrolledField

4.3.24. ScrolledFrame

4.3.25. ScrolledListbox

4.3.26. ScrolledText

4.3.27. SelectionDialog

4.3.28. TextDialog

4.3.29. TimeCounter

4.4. Creating new megawidgets

4.4.1. Description of the megawidget

4.4.2. Options

4.4.3. Creating the megawidget class

5. Screen layout

5.1. Introduction to layout

5.1.1. Geometry management

5.2. Packer

5.2.1. Using the expand option

5.2.2. Using the fill option

5.2.3. Using the padx and pady options

5.2.4. Using the anchor option

5.2.5. Using hierarchical packing

5.3. Grid

5.4. Placer

5.5. Summary

6. Events, bindings and callbacks

6.1. Event-driven systems: a review

6.1.1. What are events?

6.1.2. Event propagation

6.1.3. Event types

6.2. Tkinter events

6.2.1. Events

6.3. Callbacks

6.4. Lambda expressions

6.4.1. Avoiding lambdas altogether

6.5. Binding events and callbacks

6.5.1. Bind methods

6.5.2. Handling multiple bindings

6.6. Timers and background procedures

6.7. Dynamic callback handlers

6.8. Putting events to work

6.8.1. Binding widgets to dynamic data

6.8.2. Data verification

6.8.3. Formatted (smart) widgets

6.9. Summary

7. Using classes, composites and special widgets

7.1. Creating a Light Emitting Diode class

7.1.1. Let’s try that again

7.1.2. What has changed?

7.2. Building a class library

7.2.1. Adding a hex nut to our class library

7.2.2. Creating a switch class

7.2.3. Building a MegaWidget

7.3. Summary

8. Dialogs and forms

8.1. Dialogs

8.1.1. Standard dialogs

8.1.2. Data entry dialogs

8.1.3. Single-shot forms

8.1.4. Tkinter variables

8.2. A standard application framework

8.3. Data dictionaries

8.4. Notebooks

8.5. Browsers

8.6. Wizards

8.7. Image maps

8.8. Summary

9. Panels and machines

9.1. Building a front panel

9.2. Modularity

9.3. Implementing the front panel

9.4. GIF, BMP and overlays

9.5. And now for a more complete example

9.6. Virtual machines using POV-Ray

9.6.1. And now for something completely different…​ #10 The Example

9.7. Summary

10. Drawing blobs and rubber lines

10.1. Drawing on a canvas

10.1.1. Moving canvas objects

10.2. A more complete drawing program

10.3. Scrolled canvases

10.4. Ruler-class tools

10.5. Stretching canvas objects

10.6. Some finishing touches

10.7. Speed drawing

10.8. Summary

11. Graphs and charts

11.1. Simple graphs

11.2. A graph widget

11.2.1. Adding bargraphs

11.2.2. Pie charts

11.3. 3-D graphs

11.4. Strip charts

11.5. Summary

12. Navigation

12.1. Introduction: navigation models

12.2. Mouse navigation

12.3. Keyboard navigation: 'mouseless navigation'

12.4. Building navigation into an application

12.5. Image maps

12.6. Summary

13. The window manager

13.1. What is a window manager?

13.2. Geometry methods

13.3. Visibility methods

13.4. Icon methods

13.5. Protocol methods

13.6. Miscellaneous wm methods

Part 3 Putting it all together…​

14. Extending Python

14.1. Writing a Python extension

14.2. Building Python extensions

14.2.1. Linking an extension statically in Unix

14.2.2. Linking an extension statically in Windows

14.2.3. Building a dynamic module in Unix

14.2.4. Building a dynamic module in Windows

14.2.5. Installing dynamic modules

14.2.6. Using dynamic modules

14.3. Using the Python API in extensions

14.4. Building extensions in C++

14.5. Format strings

14.6. Reference counts

14.7. Embedding Python

14.8. Summary

15. Debugging applications

15.1. Why print statements?

15.2. A simple example

15.3. How to debug

15.4. A Tkinter explorer

15.5. pdb

15.6. IDLE

15.7. DDD

16. Designing effective graphics applications

16.1. The elements of good interface design

16.2. Human factors

16.2.1. Choosing fonts

16.2.2. Use of color in graphical user interfaces

16.2.3. Size considerations

16.3. Alternative graphical user interfaces

16.4. Summary

17. Programming for performance

17.1. Everyday speedups

17.1.1. Program organization

17.1.2. Using the Python optimizer

17.1.3. Examining code

17.2. Tkinter performance

17.2.1. Keep it short!

17.2.2. Eliminate local variables

17.2.3. Keep it simple

17.2.4. Fast initialization

17.2.5. Throttling events

17.3. Python techniques

17.3.1. Importing modules

17.3.2. Concatenating strings

17.3.3. Getting nested loops right

17.3.4. Eliminate module references

17.3.5. Use local variables

17.3.6. Using exceptions

17.3.7. Using map, filter and reduce

17.4. Application profiling

17.5. Python extensions

17.6. Summary

18. Threads and asynchronous techniques

18.1. Threading

18.1.1. Non-GUI threads

18.1.2. GUI threads

18.2. 'after' processing

18.3. Summary

19. Distributing Tkinter applications

19.1. General issues in distributing applications

19.2. Distributing Unix applications

19.3. Distributing Win32 applications

19.4. Python distribution tools

Part 4 Appendices

Appendix A: Mapping Tk to Tkinter

Appendix B: Tkinter reference

Appendix C: Pmw reference: Python megawidgets

Appendix D: Building and installing Python, Tkinter

Appendix E: Events and keysyms

Appendix F: Cursors

Appendix G: References


About the reader

This book is designed for readers who are familiar with Python and who need to develop applications with Graphical User Interfaces (GUIs).

About the author

John Grayson is a consultant for GUI applications. He has been supporting application design at a large US communications company for several years, designing innovative interfaces and introducing Python and OOP to traditional development methods. He has been working with Python since 1993 and has built real-world applications for the State of Florida, State of Georgia and several US airlines.

placing your order...

Don't refresh or navigate away from the page.
print book $39.96 $49.95 pBook + PDF
Additional shipping charges may apply
Prints and ships within 3-5 days
Python and Tkinter Programming (print book) added to cart
continue shopping
go to cart

eBook $31.99 $39.99 PDF only
Python and Tkinter Programming (eBook) added to cart
continue shopping
go to cart

Prices displayed in rupees will be charged in USD when you check out.

FREE domestic shipping on three or more pBooks