Changing images and Timers in Tkinter

moonlite56 at yahoo.com moonlite56 at yahoo.com
Mon Aug 13 21:10:02 EDT 2001


First: I am learning how to use images in Tkinter, and I am creating 
a little test program that lets you change the outfits of little 
people. I wondered if you can change the file used by one image. 
This would allow me to change the image file without making a large 
number of images. Here's what I have right now (changeimage is the 
function that changes the outfit):

   top = Tk()
   top.title("Kuti")
   top.geometry("200x100")

   iKuti = ImageTk.PhotoImage(Image.open("body/lighttan.gif"))
   iKuti2 = ImageTk.PhotoImage(Image.open("hair/brownbuns.gif"))
   iKuti3 = ImageTk.PhotoImage(Image.open("outfit/whiteblouse.gif"))

   cpic = Canvas(width = 40, height = 40)
   cpic.grid(column = 0, row = 0, columnspan = 2)

   cpic.create_image(0, 0, anchor = NW, image = iKuti)
   cpic.create_image(0, 0, anchor = NW, image = iKuti2)
   cpic.create_image(0, 0, anchor = NW, image = iKuti3)

   bChange = Button(top, text = "Change", width = 10, command = 
changeimage)
   bChange.grid(row = 1, column = 0)
   bQuit = Button(top, text = "Quit", width = 10, command = top.quit)
   bQuit.grid(row = 1, column = 1)

   top.mainloop()

Second: I am also creating a little vitual pet that updates its mood 
and image every second or so. Basicly, it uses a timer. I used them 
a lot in Visual Basic, and I wondered if there was such a thing in 
Tkinter. I don't know how time.sleep() would work, and it seems I 
need an event. Is there a way to do this?






More information about the Python-list mailing list