Changing image in label
2rkil at my-deja.com
2rkil at my-deja.com
Fri Dec 8 04:28:41 EST 2000
Hi.
I'm totally new to, yet amazed by, Python. I'm
trying to
write a program which displays a portrait, asking
the
user who it is. After answering, the picture
should change
to another person, and so on.
Probably simple, but I'm new to event based
programming.
What happens is that the first picture disappears,
and just
the frame (the sizes) of the new one appears.
Here's the code:
#!/usr/bin/python
from Tkinter import *
import string
root = Tk()
def getquestion():
return "gfx/torkil_grindstein.gif", "Who is
this?", "Torkil Grindstein"
def getquestion2():
return "gfx/haakon_brugaard.gif", "But who is
this?", "Håkon Brugård"
def update(event):
global photo_widget, question_widget
photo, question, fasit = getquestion2()
gif = PhotoImage(file=photo)
photo_widget["image"] = gif
question_widget["text"] = question
def main():
global photo_widget, question_widget,
answer_widget
photo, question, fasit = getquestion()
gif = PhotoImage(file=photo)
photo_widget = Label(root, relief=RAISED,
image = gif)
photo_widget.pack()
question_widget = Label(root, text = question)
question_widget.pack()
f = Frame(root)
f.pack()
answer_widget = Entry(f)
answer_widget.bind("<Return>", update)
answer_widget.pack(side=LEFT)
answer_button = Button(f, text="Answer")
answer_button.bind("<Button>", update)
answer_button.pack(side=LEFT)
root.mainloop()
if __name__ == "__main__":
main()
-------
If I, however, put a bogus line at the end of
update(), the
program naturally crashes, but then the correct
image is
shown!
Hope anyone can spot my incompetance...
Torkil
Sent via Deja.com http://www.deja.com/
Before you buy.
More information about the Python-list
mailing list