Differences between revisions 3 and 106 (spanning 103 versions)
Revision 3 as of 2002-09-26 15:40:25
Size: 980
Editor: 213
Comment:
Revision 106 as of 2011-05-28 14:33:35
Size: 7570
Editor: 94-193-193-138
Comment:
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
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 Python's de-facto standard GUI (Graphical User Interface) package. It is a thin object-oriented layer on top of [[http://tcl.sourceforge.net/|Tcl/Tk]].
Line 3: Line 3:
Tkinter is not the only GuiProgramming toolkit for Python. It is however the most commonly used one, and almost the only one that is portable between Unix, Mac and Windows. CameronLaird calls the yearly decision to keep TkInter "one of the minor traditions of the Python world."  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 5: Line 5:
More info here: http://www.python.org/topics/tkinter/ The Tkinter wiki: http://tkinter.unpythonic.net/wiki/
Line 8: Line 8:
  * [[http://www.pythonware.com/library/tkinter/introduction/|An Introduction To Tkinter]] (online) by 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). 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]]
David McNab recommended the latter two as particularly "pythonic" in not insisting that readers think in Tcl.
 * [[http://www.ferg.org/thinking_in_tkinter/index.html|Thinking in Tkinter]] is an introduction to some basic Tkinter programming concepts.
Line 9: Line 17:
     * [http://www.pythonware.com/library/index.htm An Introduction To Tkinter] (online) by FredrikLundh  * [[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]]..
Line 12: Line 19:
  * DEAD: [http://www.amk.ca/bookstore/applications.html Python and Tkinter Programming] by JohnGrayson  * [[http://www.tcl.tk/man/|Online Tcl/Tk Manual Pages]] - the official man pages at the Tcl Developer Xchange.
Line 14: Line 21:
Also see: http://www.python.org/topics/tkinter/doc.html
 * 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.

 * The ''Tkinter Life Preserver'', by Matt Conway is still useful, though way out of date. It's the only document that explains how to read the Tcl/Tk manuals and translate the information there to Tkinter calls. [[http://www6.uniovi.es/python/doc/life-preserver/index.html|HTML version]], converted by Ken Manheimer.

 * The source: when all else fails: Read The Source, Luke!
        * ''Demo/tkinter/'' in the Python source distribution.
          This contains many helpful examples, including updated
          versions of Matt Conway's examples.
        * ''Lib/lib-tk/Tkinter.py'' in any Python distribution.


 * Other prominent Tcl/Tk sites:

        * [[http://www.tcl.tk|Tcl Developer Xchange]]
        * [[http://sourceforge.net/projects/tcl|Tcl project at SourceForge]]
        * [[http://sourceforge.net/foundry/tcl-foundry|Tcl foundry at SourceForge]](2008/09/07 lost link?)

 * Other Tcl/Tk related links:

        * [[http://pypi.python.org/pypi/pytkgen|Simple toolsuite to create Tkinter GUIs on the fly from JSON files]]
Line 18: Line 47:
  * ["Pmw"] (http://pmw.sourceforge.net)
  * ["Tix"]
  * ["Tkinter3000"] (http://tkinter.effbot.org)
  * [[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 24: Line 55:
MythDebunking: ''TkInter is ugly on Windows.'' 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.


---- /!\ '''Edit conflict - other version:''' ----
 * 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. [http://idolwhitereviews.blog.com/|idol white]

---- /!\ '''Edit conflict - your version:''' ----
 * 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. [http://idolwhitereviews.blog.com/|idol white]

---- /!\ '''End of edit conflict''' ----

 * 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 following command at the Python prompt:

{{{>>> import Tkinter # no underscore, uppercase 'T' prior to V3.0; lowercase 't' from v3.0}}}

 * If it works, go to step 3.


---- /!\ '''Edit conflict - other version:''' ----
 * 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").

---- /!\ '''Edit conflict - your version:''' ----
 * 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").

---- /!\ '''End of edit conflict''' ----

=== Step 3 - does Tkinter work? ===

Try the following command at the Python prompt:

{{{>>> Tkinter._test() # note underscore in _test. Also, if you are using Python 3.1, try tkinter._test() instead.}}}

 * 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. Move it aside or locate the Tk window in the Taskbar.)

 * If this doesn't work, study the error message you get; if you can't see how to fix the problem, [[news:comp.lang.python|ask for help]].

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."

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

Tkinter Documentation

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

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.


/!\ Edit conflict - other version:


  • 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. [http://idolwhitereviews.blog.com/|idol white]


/!\ Edit conflict - your version:


  • 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. [http://idolwhitereviews.blog.com/|idol white]


/!\ End of edit conflict


  • 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 following command at the Python prompt:

>>> import Tkinter # no underscore, uppercase 'T' prior to V3.0; lowercase 't' from v3.0

  • If it works, go to step 3.


/!\ Edit conflict - other version:


  • 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").


/!\ Edit conflict - your version:


  • 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").


/!\ End of edit conflict


Step 3 - does Tkinter work?

Try the following command at the Python prompt:

>>> Tkinter._test() # note underscore in _test. Also, if you are using Python 3.1, try tkinter._test() instead.

  • 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. Move it aside or locate the Tk window in the Taskbar.)
  • If this doesn't work, study the error message you get; if you can't see how to fix the problem, ask for help.

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

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