[Python-de] Re: [Tutor] Images + Tkinter

Gregor Lingl glingl at aon.at
Sun Nov 17 09:32:38 EST 2002


Hallo Hans,

your example (see below) seems indeed to be very strange
and counterintuitive.
I can't explain it.
But I made the following two observations:

1. The following code displays the rectangle but not the image:

import Tkinter,
from Tkconstants import *

def window(tk):
    frame=Tkinter.Frame(tk)
    frame.pack()
    canvas=Tkinter.Canvas(frame,width=400,height=500)
    photo=Tkinter.PhotoImage(file="boat.gif")
    canvas.create_image(200, 250, image=photo)
    canvas.create_rectangle(10,20,30,40,fill="red")
    canvas.pack()
    button=Tkinter.Button(frame, text="EXIT", command=tk.destroy)
    button.pack() 
    # tk.mainloop()  # ?????????????????????????

root = Tkinter.Tk()
window(root)
root.mainloop()

2. The following code displays the image:

import Tkinter
from Tkconstants import *

def window(tk,photo):
    frame=Tkinter.Frame(tk)
    frame.pack()
    canvas=Tkinter.Canvas(frame,width=400,height=500)
    canvas.create_image(200, 250, image=photo)
    canvas.pack()
    button=Tkinter.Button(frame, text="EXIT", command=tk.destroy)
    button.pack() 
    # tk.mainloop()  # ?????????????????????????

root = Tkinter.Tk()
photo=Tkinter.PhotoImage(file="boat.gif")
window(root, photo)
root.mainloop()

Does anybody know the secrets, which lie behind this mystery?
Gregor


Hans Gubitz schrieb:

>Hello,
>
>tk.mainloop() seems to be not in the right place. But the gif will not
>be shown, when I eliminate this line.
>
>Any hints?
>
>
>
>import Tkinter
>from Tkconstants import *
>
>def window(tk):
>    frame=Tkinter.Frame(tk)
>    frame.pack()
>    canvas=Tkinter.Canvas(frame,width=400,height=500)
>    photo=Tkinter.PhotoImage(file="picture.gif")
>    canvas.create_image(200, 250, image=photo)
>    canvas.pack()
>    button=Tkinter.Button(frame, text="EXIT", command=tk.destroy)
>    button.pack()
>    
>    tk.mainloop()  # ?????????????????????????
>
>root = Tkinter.Tk()
>window(root)
>root.mainloop()
>
>
>
>Hans Gubitz <gubitz at netcologne.de>
>
>
>_______________________________________________
>Tutor maillist  -  Tutor at python.org
>http://mail.python.org/mailman/listinfo/tutor
>
>
>  
>








More information about the Python-de mailing list