[Tutor] How Do I Put an Image on a Canvas and Display it?
Alan Gauld
alan.gauld at btinternet.com
Mon Jan 26 19:00:13 CET 2009
"Wayne Watson" <sierra_mtnview at sbcglobal.net> wrote
>>>> Image
> <class Image.Image at 0x00EA5720>
>>>> help(Image)
> Help on class Image in module Image:
> ...
> This is definitely different than the Tkimage help you showed.
> So what's happening?
You import your Image module as Image.
Then you import all; the names from Tkinter which includes the
name Image. Thus the Tkinter Imahe hides the original
imported Image.
You need to either
import Image as im # or some other alias
or not use from Tkinter, ie use
import Tkinter as T
Then use T.Image to refer to the Tkinter Image and im to
refer to the imported Image module
Its all about controlling namespaces.
It is exactly because of these kinds of problems that the
from X import * style is considered a bad idea.
(In Tkinter it usually works because the names are pretty
GUI specific but if, as you are doing, you mix GUI and
graphics you get overlaps.
> How do I use the two Image classes to navigate between
> an image that uses PIL methods and one than uses Tkinter?
Just use the appropriate module prefix (or an alias)
See the namespaces topic in my tutor for a refresher
on namespaces! :-)
--
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld
More information about the Tutor
mailing list