Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Python (http://www.velocityreviews.com/forums/f43-python.html)
-   -   Tkinter Button image option (http://www.velocityreviews.com/forums/t329767-tkinter-button-image-option.html)

Elaine Jackson 04-11-2004 03:47 AM

Tkinter Button image option
 
When I try to put an image onto a Tkinter button, I get a message that says the
image in question "doesn't exist" (it does, though). One of the references I
looked at said that Tkinter has to be "configured for" the Python Imaging
Library in order for the 'image' option to work. I've got the PIL, but as for
"configuration", I don't know. Maybe I need to reinstall Tcl/Tk? If anyone can
point me to the appropriate resource, I'd be very much obliged.
Peace



Mike Abel 04-11-2004 06:56 AM

Re: Tkinter Button image option
 
Elaine Jackson <elainejackson7355@home.com> wrote:

Hi Elaine,

i think you use not the correct path to the image?

For an example look at the following url.
Sorry it's a german site.

http://home.foni.net/~heikos/tkinter/node56.html

Mike

Jason Harper 04-11-2004 05:04 PM

Re: Tkinter Button image option
 
Are you saving a reference to the image you loaded somewhere (perhaps as
an attribute of the button, if that's the only user of the image)?
Merely using an image in a Tkinter widget is NOT sufficient to keep it
from being garbage collected.

PIL is not required for basic use of images in Tkinter, although it does
give you lots more options for working with them.
Jason Harper

Elaine Jackson 04-11-2004 06:11 PM

Re: Tkinter Button image option
 

"Mike Abel" <Ax10@gmx.de> wrote in message
news:dp6nk1-4u1.ln1@6.mabelsoft.org...
<snip>
| Sorry it's a german site.

Kein Problem. Ganz im Gegenteil: ich habe den genau richtigen Hinweis gefunden.
Danke vielmals!



Fredrik Lundh 04-16-2004 11:05 AM

Re: Tkinter Button image option
 
Elaine Jackson wrote:

> When I try to put an image onto a Tkinter button, I get a message that

says the
> image in question "doesn't exist" (it does, though). One of the references

I
> looked at said that Tkinter has to be "configured for" the Python Imaging
> Library in order for the 'image' option to work. I've got the PIL, but as

for
> "configuration", I don't know. Maybe I need to reinstall Tcl/Tk? If anyone

can
> point me to the appropriate resource, I'd be very much obliged.


did you get an error similar to this:

TclError: image "pyimage1" doesn't exist

a common reason for this is that you have multiple Tk instances in
your application.

if you create a PhotoImage under one Tk instance, you cannot access
it from other instances.

to fix this, make sure you only use one Tk instance (use Toplevel to create
new toplevel windows), or make sure that you create the image under the
same instance as the widget you're going to use it in. the easiest way to
do
this is to pass in a master keyword argument to the PhotoImage constructor:

photo = PhotoImage(..., master=myroot)
button = Button(myroot, ...)
button.photo = photo # keep a reference

(if the file you're trying to load doesn't exist,

</F>






All times are GMT. The time now is 03:51 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.