I think your question comes from trying to work through Python Programming from John Celle using a Macintosh.
The first 4 chapters are great. But in chapter 5, where I was usually stuck, he introduces objects. The way he does this is quite interesting. He created a python module, which he calls "graphics.py", which you can download from his website.
This module (Ive attached a link to it below) is a python program written by Mr. Celle. He creates tools for creating very simple shapes and gets used to basic concepts with graphics, and also serves as a more tangible way to introduce objects.
However, I was confused, it took me a while to realize that "graphics.py" is a pedagogical program created by Mr. Celle, and not what comes with MacPython. This confusion stems from the fact that the programs in chapter 5 start with “import graphics,” which is very similar to the “import math” command at the beginning of each program in chapter three.
The key difference is that “import math” imports the standard math library that comes with MacPython. But "import graphics" refers to John Cellles' own graphics.py module, which you must first download and install.
It took me a while to figure this out ...
Then, as soon as I did this, I went to his site, copied the program from this site:
http://mcsp.wartburg.edu/zelle/python/graphics.py
... in IDLE and then saved it as graphics.py
That's where he went crazy ...
On Windows, if you just put the graphics.py file in the same folder as Python, it can find the file and use it without problems.
This is what the book said, and it made me feel so crazy:
"To use the graphics module (graphics.py), you need to put this file where Python can find it.> One simple approach is to put it in the same folder where you keep your Python programs. Starting> Python in this folder will also allow you to import a graphics library for interactive experimentation.Also, you can put the graphics.py file in the system-wide directory so that it is available for import no matter what directory Python runs in. The standard directory for locating local The Python directory is the directory of package sites. In my Windows installation, the full path to the folder is:
C: \ Python23 \ Lib \ Site Packages
On my Linux system, the file is located in:
/usr/local/bin/lib/python2.3/site-packages ".
On Windows, all you have to do is go to Python.org and download Python for Windows and put this graphics.py file in the main folder, and boom, youre golden, NOT SO FOR MACINTOSH !!!
2 years ago, here I was completely stuck because I had no idea about site tracks or directories; I just pointed and clicked; I did not know about the Unix system under the Macintosh Aqua GUI.
And the book does not give any instructions on what to do if you have a Macintosh and I hit a wall.
But when I switched to it again a few weeks ago, these directories made more sense to me because I spent spring and summer playing with a guide to use the UNIX command shell on my Mac.
So, I realized that my problem has nothing to do with Tkinter, I just need graphics.py to be in the correct directory. I could not just put it in the folder next to IDLE, as I could, on a Windows machine. I needed to find the correct directory.
Since OSX is built on top of UNIX, I thought the file path might be the same as Linux. Unfortunately, after the "user" directory there was no "local", "bin". But this is not exactly the same in OSX.
Instead, you can use IDLE yourself to find out which path directories it uses.
You enter this:
import sys
print sys.path
and BOOM, it spills out a whole bunch of directories vaguely formatted this way
['', '/ Users / jamesbarnard / Documents',' /Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip ',' /Library/Frameworks/Python.framework/Versions/2.7/lib/ python2.7 ',' / Library / Frameworks / Python.framework / Versions / 2.7 / lib / python2.7 / plat-darwin ',' / Library / Frameworks / Python.framework / Versions / 2.7 / lib / python2.7 / plat-mac ',' / Library / Frameworks / Python.framework / Versions / 2.7 / lib / python2.7 / plat-mac / lib-scriptpackages ',' / Library / Frameworks / Python.framework / Versions / 2.7 / lib / python2.7 / lib-tk ',' / Library / Frameworks / Python.framework / Versions / 2.7 / lib / python2.7 / lib-old ',' / Library / Frameworks / Python.framework / Versions / 2.7 / lib / python2.7 / lib-dynload ',' / Library / Frameworks / Python.framework / Versions / 2.7 / lib / python2.7 / site-packages, "/Library/Python/2.7/site-packages]
But when I came closer, I noticed the site-packages directory, which looked a lot like site-packages on the Linux and Windows command line. So I pulled out the directory chain
['', '/ Users / jamesbarnard / Documents',' /Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip ',' /Library/Frameworks/Python.framework/Versions/2.7/lib/ python2.7 ',' / Library / Frameworks / Python.framework / Versions / 2.7 / lib / python2.7 / plat-darwin ',' / Library / Frameworks / Python.framework / Versions / 2.7 / lib / python2.7 / plat-mac ',' / Library / Frameworks / Python.framework / Versions / 2.7 / lib / python2.7 / plat-mac / lib-scriptpackages ',' / Library / Frameworks / Python.framework / Versions / 2.7 / lib / python2.7 / lib-tk ',' / Library / Frameworks / Python.framework / Versions / 2.7 / lib / python2.7 / lib-old ',' / Library / Frameworks / Python.framework / Versions / 2.7 / lib / python2.7 / lib-dynload, '/Library/Frames/Python.framework/Versions/2.7/lib/python2.7/site-packages', ' / Library / Python / 2.7 / site-packages]
Then, using the UNIX shell, I followed it, and then I did the same in the Aqua interface.
And there, immersed 8 levels down in the directory, among hundreds of other files, I placed my graphics.py file.
Then I returned to IDLE, typed "import graphics"
AND THIS WORKS !!
If you have this problem. I hope this solution saves you from a headache.