Is there a known Win32 Tkinter bug with respect to displaying photos on a canvas? Is there a known Win32 Tkinter bug with respect to displaying photos on a canvas? tkinter tkinter

Is there a known Win32 Tkinter bug with respect to displaying photos on a canvas?


Do that as a quick solution, and I'll try to explain:

def set_canvas(cv):    global photo # here!    photo=PhotoImage(file=sys.argv[1])    cv.create_image(0, 0, image=photo, anchor=NW)  # embed a photo    print cv    print photo

A PhotoImage needs to have at least one reference from any Python object, otherwise it's garbage collected. In my solution, I suggest to make photo be a module-level name, so when the function ends, there will still be a reference to the PhotoImage object. You might prefer to create a class and make set_canvas into a method, and store the PhotoImage object as an instance variable.