Tkinter Button image option

Discussion in 'Python' started by Elaine Jackson, Apr 11, 2004.

  1. 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
    Elaine Jackson, Apr 11, 2004
    #1
    1. Advertising

  2. Elaine Jackson

    Mike Abel Guest

    Mike Abel, Apr 11, 2004
    #2
    1. Advertising

  3. Elaine Jackson

    Jason Harper Guest

    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
    Jason Harper, Apr 11, 2004
    #3
  4. "Mike Abel" <> wrote in message
    news:...
    <snip>
    | Sorry it's a german site.

    Kein Problem. Ganz im Gegenteil: ich habe den genau richtigen Hinweis gefunden.
    Danke vielmals!
    Elaine Jackson, Apr 11, 2004
    #4
  5. 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>
    Fredrik Lundh, Apr 16, 2004
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Julien ROUZIERES

    g++ -pg option and -shared option

    Julien ROUZIERES, Dec 21, 2004, in forum: C++
    Replies:
    1
    Views:
    704
    GianGuz
    Dec 21, 2004
  2. Cas
    Replies:
    5
    Views:
    781
    Kevin Jones
    Aug 28, 2006
  3. Kevin Blount

    page.aspx?option - how to detect "option"

    Kevin Blount, Nov 28, 2006, in forum: ASP .Net
    Replies:
    6
    Views:
    596
    =?Utf-8?B?RWVyYWo=?=
    Nov 28, 2006
  4. John

    Regex for <option> ... </option>

    John, Jan 23, 2009, in forum: Perl Misc
    Replies:
    10
    Views:
    229
    Eric Pozharski
    Jan 29, 2009
  5. Mark Kolber
    Replies:
    4
    Views:
    330
Loading...

Share This Page