Tkinter, image not appearing in function but without function

skanemupp at yahoo.se skanemupp at yahoo.se
Sun Apr 13 11:57:29 EDT 2008


why is the first program not working? when i click the screen the map
is not appearing.

the second program works.



from Tkinter import *

master = Tk()

w = Canvas(master, width=700, height=600)
w.pack(expand = YES, fill = BOTH)

def mapper():
    mapq = PhotoImage(file = 'C:\Users\saftarn\Desktop\world-map.gif')
    w.create_image(10, 10, image = mapq, anchor = NW)

def key(event):
    print "pressed", repr(event.char)

def callback(event):
    w.focus_set()
    print "clicked at", event.x, event.y
    mapper()
    print 'yo'
    square = w.create_oval(event.x-5,event.y-5,event.x+5,event.y+5,
fill="black")

w.bind("<Key>", key)
w.bind("<Button-1>", callback)
w.pack()


mainloop()




from Tkinter import *

master = Tk()


w = Canvas(master, width=700, height=600)
w.pack(expand = YES, fill = BOTH)

q=raw_input("Choose: i=India, s=sweden, else World: ")
if q=="i":
    mapq = PhotoImage(file = 'C:\Users\saftarn\Desktop\map-india.bmp')
elif q=='s':
    mapq = PhotoImage(file = 'C:\Users\saftarn\Desktop\provinces-of-
sweden.gif')
else:
    mapq = PhotoImage(file = 'C:\Users\saftarn\Desktop\world-map.gif')

print mapq.height(), mapq.width()
w.create_image(10, 10, image = mapq, anchor = NW)

def key(event):
    print "pressed", repr(event.char)

def callback(event):
    w.focus_set()
    print "clicked at", event.x, event.y
    square = w.create_oval(event.x-5,event.y-5,event.x+5,event.y+5,
fill="black")

"""hur hitta om inom ratt->kolla color of """

w.bind("<Key>", key)
w.bind("<Button-1>", callback)
w.pack()

mainloop()



More information about the Python-list mailing list