Tkinter ('Tk Interface')is python's standard cross-platform package for creating graphical user interfaces (GUIs). It provides access to an underlying Tcl interpreter with the Tk toolkit, which itself is a cross-platform, multilanguage graphical user interface library.
Tkinter is a graphical user interface (GUI) module for Python, you can make desktop apps with Python. You can make windows, buttons, show text and images amongst other things.
Tk and Tkinter apps can run on most Unix platforms. This also works on Windows and Mac OS X.
The module Tkinter is an interface to the Tk GUI toolkit.
Related course:Python Desktop Apps with Tkinter
Example
Tkinter module
This example opens a blank desktop window. The tkinter module is part of the standard library.
To use tkinter, import the tkinter module.
This is tkinter with underscore t, it has been renamed in Python 3.
Setup the window
Start tk and create a window.
The window class is not standard, we create a Window. This class in itself is pretty basic.
Then set the window title and show the window:
Tkinter window example
The program below shows an empty tkinter window.
Run with the program below:
I am looking for a complete online reference for Python's tkinter
module. I've tried to find one by myself, but for some reason I can't.
To clarify, I am not looking for a tutorial. Instead, I would like to have a reference for all the available classes and attributes.
For example, if I write this code:
Python And Tkinter Programming Pdf
I wonder: what optional arguments does the Tk
class accept for instantiation? What are properties and methods for a Tk
object? What arguments does title
accept? And so on...
'Look at the source' is not an answer to this question, obviously.
Steven M. VascellaroPython Gui Programming With Tkinter Pdf
5 Answers
I found this reference useful - not always perfect, but usually useful: http://infohost.nmt.edu/tcc/help/pubs/tkinter/index.html
Also contains explanations of layout management and the event model. Since it's for Python 2.5, the code examples won't run out of the box on Python 3, but the method names shouldn't have changed, only the modules were renamed and reorganized (the tk*
modules containing popups are now in the tkinter
package).
For a definitive guide to all of the options supported by each widget you should consult the tcl/tk documentation. It's a fairly trivial mental exercise to translate the tcl into python. The only real problems are when the tcl options conflict with python reserved words (such as the -in
option for pack and grid)
There were 2 books that were very useful to me:
Mark Roseman's Modern Tkinter for Busy Python Programmers
John Grayson's Python and Tkinter Programming.
They are very complete. They might be hard to find online.
nbroI'm adding an alternative answer by myself:
I could just use pydoc
to have the complete module reference.
Some links no longer function - lately I've been relying on effbot for all my tkinter documentation needs.