OS X and Tkinter

M

Mike Tuller

I recently purchased a book to learn python, and am at a part where I
want to start working with GUIs. I have an OS X system, and am using
the default python installed on the system. I have installed Tcl/Tk
Aqua from http://tcltkaqua.sourceforge.net/.

When I run the file called gui.py that contains this:

from Tkinter import *
root = Tk()
root.title("Simple GUI")
root.geometry("200x100")

I get this back:

python gui.py
Traceback (most recent call last):
File "gui.py", line 1, in ?
from Tkinter import *
File
"/System/Library/Frameworks/Python.framework/Versions/2.3/lib/
python2.3/lib-tk/Tkinter.py", line 38, in ?
import _tkinter # If this fails your Python may not be configured
for Tk
ImportError: No module named _tkinter

I have looked everywhere on the net, and can't figure out how to
configure python so that Tkinter will work with it. Any help would be
appreciated.


Mike
 
R

Robert Kern

Mike said:
I recently purchased a book to learn python, and am at a part where I
want to start working with GUIs. I have an OS X system, and am using
the default python installed on the system. I have installed Tcl/Tk
Aqua from http://tcltkaqua.sourceforge.net/.

Download and install

http://www.pythonmac.org/packages/MacPythonPantherAddons-2-py2.3-macosx10.3.zip

It will install the _tkinter extension module.

--
Robert Kern
(e-mail address removed)

"In the fields of hell where the grass grows high
Are the graves of dreams allowed to die."
-- Richard Harter
 
P

Piet van Oostrum

Mike Tuller said:
MT> I recently purchased a book to learn python, and am at a part where I want
MT> to start working with GUIs. I have an OS X system, and am using the
MT> default python installed on the system. I have installed Tcl/Tk Aqua from
MT> http://tcltkaqua.sourceforge.net/.
MT> When I run the file called gui.py that contains this:
MT> from Tkinter import *
MT> root = Tk()
MT> root.title("Simple GUI")
MT> root.geometry("200x100")
MT> I get this back:
MT> python gui.py
MT> Traceback (most recent call last):
MT> File "gui.py", line 1, in ?
MT> from Tkinter import *
MT> File "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/
MT> python2.3/lib-tk/Tkinter.py", line 38, in ?
MT> import _tkinter # If this fails your Python may not be configured for
MT> Tk
MT> ImportError: No module named _tkinter
MT> I have looked everywhere on the net, and can't figure out how to configure
MT> python so that Tkinter will work with it. Any help would be appreciated.

You need to install Tkinter. The easiest way is to use the Python Package
Manager: http://www.python.org/packman/
 
S

scott

Mike said:
I have looked everywhere on the net, and can't figure out how to
configure python so that Tkinter will work with it. Any help would be
appreciated.

The following worked for me with OSX version 10.3 and the default python
2.3:

http://www.pythonmac.org/wiki/FAQ#head-8838d40da5d563166ca8b13cfb71cd2e856e81e3

"
5.5 How do I install Tkinter? How do I get IDLE to work?

Here are the steps for installing Tkinter:
• Download and install TclTkAqua
• Download and install the MacPythonPantherAddons if you are using
the version of Python 2.3 included with OS X 10.3
• Open PackageManager, it is located in /Applications/MacPython-2.3
• Install _tkinter

You may then use Tkinter based applications such as IDLE, which should
also be available from PackageManager. Note that if you are running any
sort of GUI application from Terminal, you must use "pythonw" not
"python" to launch the script.

If the PackageManager complains that it cannot open a certain URL at
www.python.org, choose "Open URL" from the "File" menu and open
http://www.python.org/packman/version-0.3/darwin-7.7.0-Power_Macintosh.plist
instead of the standard URL.
"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top