[Tutor] Images + Tkinter

Hans Gubitz gubitz@netcologne.de
Sun Nov 17 08:53:01 2002



On Sun, Nov 17, 2002 at 01:05:22PM +0100, Gregor Lingl wrote:
> Martin v. Loewis has sent me the following explanation:
...


With this explanation I found two solutions:


1)

import Tkinter
from Tkconstants import *

def fenster(tk):
    frame=Tkinter.Frame(tk)
    frame.pack()
    photo=Tkinter.PhotoImage(file="bluecher.gif")
    canvas=Tkinter.Canvas(frame,width=400,height=500,bg="blue")
    canvas.create_image(200, 250, image=photo)
    canvas.pack()
    button=Tkinter.Button(frame, text="EXIT", command=tk.destroy)
    button.pack()
    return photo
    
tk = Tkinter.Tk()
ergebnis=fenster(tk)
tk.mainloop()



2)


import Tkinter
from Tkconstants import *

class Application:
    def __init__(self, master):
        frame = Tkinter.Frame(master)
        frame.pack()

        self.photo=Tkinter.PhotoImage(file="bluecher.gif")
#       ^^^^ 
        canvas=Tkinter.Canvas(frame, width=self.photo.width(), height=self.photo.height())
        canvas.create_image(0,0,anchor=NW,image=self.photo)
        canvas.pack()

        button = Tkinter.Button(frame, text = "Ende", command = master.destroy)
        button.pack()
        

tk = Tkinter.Tk()

app = Application(tk)

tk.mainloop()




Thank you

 Hans



-- 
Hans Gubitz <gubitz@netcologne.de>