Differences between revisions 136 and 148 (spanning 12 versions)
Revision 136 as of 2014-06-08 23:54:09
Size: 6975
Comment:
Revision 148 as of 2022-02-08 22:05:48
Size: 6045
Editor: martinmiller
Comment: Replaced dead links to New Mexico Institute of Mining and Technology tkinter manual.
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
#acl AdminGroup:read,write,delete,revert,admin All:read
Line 5: Line 3:
Tkinter is not the only GuiProgramming toolkit for Python. It is however the most commonly used one. CameronLaird calls the yearly decision to keep TkInter "one of the minor traditions of the Python world."
Line 6: Line 5:
Tkinter is not the only [[GuiProgramming|GuiProgramming]] toolkit for Python. It is however the most commonly used one. [[CameronLaird|CameronLaird]] calls the yearly decision to keep TkInter "one of the minor traditions of the Python world." Tkinter Documentation
Line 8: Line 7:

The Tkinter wiki: http://tkinter.unpythonic.net/wiki/


== Tkinter Documentation ==


 * [[http://www.pythonware.com/library/tkinter/introduction/|An Introduction To Tkinter]] (online) by [[FredrikLundh|FredrikLundh]]
 * [[http://infohost.nmt.edu/tcc/help/pubs/tkinter/|Tkinter reference: a GUI for Python]] (online or [[http://infohost.nmt.edu/tcc/help/pubs/tkinter/tkinter.pdf|pdf]]) by John W. Shipman, New Mexico Tech Computer Center
 * [[ISBN:1884777813|Python and Tkinter Programming]] by John Grayson (see also [[GuiBooks|GuiBooks]]). This book just recently came back into print on demand, see the publisher's website http://www.manning.com/grayson
 * [[http://modcopy.sourceforge.net/tips.html|Tips for Python/Tk]] by Andreas Balogh (about useful documentation, GUI builders and tips using Grid and HList widgets)
 * [[http://www.astro.washington.edu/users/rowen/TkinterSummary.html|Tkinter Summary]]
 * [[http://www.astro.washington.edu/users/rowen/ROTKFolklore.html|Tkinter Folklore]]
 * [[http://www.packtpub.com/tkinter-gui-application-development-hotshot/book|Tkinter GUI Application Development Hotshot]] by Bhaskar Chaudhary, published October 2013, is available in print and eBook versions. The book enables users to develop GUI applications in Python and Tkinter by working on ten real world examples.


David [[McNab|McNab]] recommended the latter two as particularly "pythonic" in not insisting that readers think in Tcl.

 * [[ISBN:1884777813|Python and Tkinter Programming]] by John Grayson (see also GuiBooks). This book just recently came back into print on demand, see the [[http://www.manning.com/grayson|publisher's website]].
 * [[https://coderslegacy.com/python/python-gui/|Python GUI with Tkinter]] is a complete tutorial that covers all the widgets for the Tkinter library, complete with examples.
 * [[https://coderslegacy.com/python/tkinter-ttk-widgets-tutorial/|Tkinter ttk Extension Tutorial]] covers the new widgets and features brought by the ttk module into Tkinter. (ttk is an extension and submodule included within Tkinter)
Line 28: Line 11:
 * [[http://docs.python.org/lib/tkinter.html|Graphical User Interfaces with Tk]], a chapter from the [[http://docs.python.org/lib/lib.html|Python Library Reference]]..  * [[http://www.tkdocs.com/tutorial/index.html|TkDocs Tutorial]], official Tkinter documentation that covers Python 3+ and Tk8.5, with easy to follow examples.
 * [[https://
docs.python.org/3/library/tk.html|Graphical User Interfaces with Tk]], a chapter from the [[https://docs.python.org/3/index.html|Python Documentation]].
Line 30: Line 14:
 * The New Mexico Institute of Mining and Technology created its own Tkinter manual. It is available in [[http://www.nmt.edu/tcc/help/pubs/tkinter/|HTML]] and [[http://www.nmt.edu/tcc/help/pubs/tkinter.pdf|PDF]].
 * [[http://www.tkdocs.com/tutorial/index.html|TkDocs Tutorial]], covers Python 3+ and Tk8.5, with easy to follow examples.
 * [[http://modcopy.sourceforge.net/tips.html|Tips for Python/Tk]] by Andreas Balogh (about useful documentation, GUI builders and tips using Grid and HList widgets).
 * The New Mexico Institute of Mining and Technology created its own Tkinter manual. It is available in [[https://tkdocs.com/shipman//|HTML]] and [[https://tkdocs.com/shipman/tkinter.pdf|PDF]].
Line 40: Line 24:
Line 46: Line 29:
Line 50: Line 32:

Line 53: Line 33:


* [[Pmw|Pmw]] (http://pmw.sourceforge.net)
 * [[Tix|Tix]] (http://www.python.org/doc/current/lib/module-Tix.html)
 * [[TkZinc|TkZinc]] (http://www.tkzinc.org)
 * [[Tkinter3000|Tkinter3000]] (http://tkinter.effbot.org)
 * [[How Tkinter can exploit Tcl/Tk extensions|How Tkinter can exploit Tcl/Tk extensions]]
 * [[Pmw]] (http://pmw.sourceforge.net)
 * [[Tix]] (http://www.python.org/doc/current/lib/module-Tix.html)
 * TkZinc (http://www.tkzinc.org)
 * [[Tkinter3000]] (http://tkinter.effbot.org)
 * [[How Tkinter can exploit Tcl/Tk extensions]]
Line 63: Line 40:


[[
MythDebunking|MythDebunking]]: ''TkInter is ugly on Windows'' (http://wiki.tcl.tk/8646)
MythDebunking: ''TkInter is ugly on Windows'' (http://wiki.tcl.tk/8646)
Line 69: Line 43:

Line 72: Line 44:
Line 76: Line 47:
Line 78: Line 48:

Line 82: Line 50:

{{{>>> import _tkinter # with underscore, and lowercase 't'}}}
{{{>>> import _tkinter # with underscore, and lowercase 't'}}}
Line 92: Line 58:
Line 94: Line 59:

Line 98: Line 61:
{{{>>> import Tkinter # no underscore, uppercase 'T' for versions prior to V3.0}}}
Line 99: Line 63:
{{{>>> import Tkinter # no underscore, uppercase 'T' for versions prior to V3.0}}}


{{{>>> import tkinter # no underscore, 
lowercase 't' for V3.0 and later}}}
{{{>>> import tkinter # no underscore, lowercase 't' for V3.0 and later}}}
Line 109: Line 69:
Line 111: Line 70:

Line 115: Line 72:
{{{>>> Tkinter._test() # note underscore in _test and uppercase 'T' for versions prior to V3.0 }}}
Line 116: Line 74:
{{{>>> Tkinter._test() # note underscore in _test and uppercase 'T' for versions prior to V3.0 }}}


{{{>>> 
tkinter._test() # note underscore in _test and lowercase 'T' for V3.0 and later}}}
{{{>>> tkinter._test() # note underscore in _test and lowercase 'T' for V3.0 and later}}}
Line 125: Line 79:

CategoryPyGUI
----
[[CategoryPyGUI]]

Tkinter is Python's de-facto standard GUI (Graphical User Interface) package. It is a thin object-oriented layer on top of Tcl/Tk.

Tkinter is not the only GuiProgramming toolkit for Python. It is however the most commonly used one. CameronLaird calls the yearly decision to keep TkInter "one of the minor traditions of the Python world."

Tkinter Documentation

Tkinter Extensions

Comments

MythDebunking: TkInter is ugly on Windows (http://wiki.tcl.tk/8646)

Checking your Tkinter support

A good way to systematically check whether your Tkinter support is working is the following.

Enter an interactive Python interpreter in a shell on an X console.

Step 1 - can _tkinter be imported?

Try the following command at the Python prompt:

>>> import _tkinter # with underscore, and lowercase 't'

  • If it works, go to step 2.
  • If it fails with "No module named _tkinter", your Python configuration needs to be modified to include this module (which is an extension module implemented in C). Do **not** edit Modules/Setup (it is out of date). You may have to install Tcl and Tk (when using RPM, install the -devel RPMs as well) and/or edit the setup.py script to point to the right locations where Tcl/Tk is installed. If you install Tcl/Tk in the default locations, simply rerunning "make" should build the _tkinter extension.
  • If it fails with an error from the dynamic linker, see above (for Unix, check for a header/library file mismatch; for Windows, check that the TCL/TK DLLs can be found).

Step 2 - can Tkinter be imported?

Try the correct command for your version at the Python prompt:

>>> import Tkinter # no underscore, uppercase 'T' for versions prior to V3.0

>>> import tkinter # no underscore, lowercase 't' for V3.0 and later

  • If it works, go to step 3.
  • If it fails with "No module named Tkinter", your Python configuration need to be changed to include the directory that contains Tkinter.py in its default module search path. You have probably forgotten to define TKPATH in the Modules/Setup file. A temporary workaround would be to find that directory and add it to your PYTHONPATH environment variable. It is the subdirectory named "lib-tk" of the Python library directory (when using Python 1.4 or before, it is named "tkinter").

Step 3 - does Tkinter work?

Try the correct command for your Python version at the Python prompt:

>>> Tkinter._test() # note underscore in _test and uppercase 'T' for versions prior to V3.0 

>>> tkinter._test() # note underscore in _test and lowercase 'T' for V3.0 and later

  • This should pop up a small window with two buttons. Clicking the "Quit" button makes it go away and the command return. If this works, you're all set. (When running this test on Windows, from Python run in a MS-DOS console, the new window somehow often pops up *under* the console window. This can also occur when using iTerm on Mac OS X. Move it aside or locate the Tk window in the Taskbar / Dock.)
  • If this doesn't work, study the error message you get; if you can't see how to fix the problem, ask for help.


CategoryPyGUI

TkInter (last edited 2022-02-08 22:05:48 by martinmiller)

Unable to edit the page? See the FrontPage for instructions.