Re: Newbie needs help with canvas.create_image !

Discussion in 'Python' started by Fredrik Lundh, Feb 12, 2005.

  1. Antti Isomursu wrote:

    > With code below I get a red box with given width and height. When I
    > use that create_image, nothing happens. I only see that same red box.
    > Why is that?
    > The loop.bmp is working fine when I use show() method.
    >
    > win = Toplevel()
    >
    > canvas = Canvas(win, width=100, height=100, background='red')
    > canvas.pack()
    >
    > im = Image.open("loop.bmp")
    > photo = ImageTk.PhotoImage(im)
    >
    > canvas.create_image(8, 8, anchor="nw", image=photo)


    the problem might be that the PhotoImage is garbage collected before being
    displayed. see the note on the bottom of this page for details:

    http://effbot.org/zone/tkinter-photoimage.htm

    </F>
     
    Fredrik Lundh, Feb 12, 2005
    #1
    1. Advertising

  2. Fredrik Lundh

    Arthur Guest

    On Sat, 12 Feb 2005 18:24:11 +0100, "Fredrik Lundh"
    <> wrote:

    >Antti Isomursu wrote:
    >
    >> With code below I get a red box with given width and height. When I
    >> use that create_image, nothing happens. I only see that same red box.
    >> Why is that?
    >> The loop.bmp is working fine when I use show() method.
    >>
    >> win = Toplevel()
    >>
    >> canvas = Canvas(win, width=100, height=100, background='red')
    >> canvas.pack()
    >>
    >> im = Image.open("loop.bmp")
    >> photo = ImageTk.PhotoImage(im)
    >>
    >> canvas.create_image(8, 8, anchor="nw", image=photo)

    >
    >the problem might be that the PhotoImage is garbage collected before being
    >displayed. see the note on the bottom of this page for details:
    >
    > http://effbot.org/zone/tkinter-photoimage.htm
    >
    ></F>


    I had run into this for the first time recently as well.

    and found this tutor thread helped.

    http://starship.python.net/pipermail/python-de/2002q4/002834.html

    Declaring "im" as global is one way to go (there I said it). In fact,
    IMO, probably the clearest (though not the prettiest) way to go under
    under the circumstances.

    I don't think anyone is particularly defending the circumstances. I
    have heard the circumstances described as a bug, and the various
    "solutions" are perhaps better thought of as work-arounds.

    Art
     
    Arthur, Feb 12, 2005
    #2
    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. Askari
    Replies:
    2
    Views:
    738
    Askari
    Aug 30, 2004
  2. PhilC
    Replies:
    2
    Views:
    927
    PhilC
    Oct 25, 2004
  3. Einar Buffer
    Replies:
    4
    Views:
    181
    Joel VanderWerf
    Jan 22, 2005
  4. Mer Gilmartin

    Newbie question Canvas or frame

    Mer Gilmartin, Oct 10, 2006, in forum: Ruby
    Replies:
    5
    Views:
    118
    Mer Gilmartin
    Oct 13, 2006
  5. Replies:
    10
    Views:
    299
    Rick Johnson
    Mar 15, 2013
Loading...

Share This Page