Sequencing images using tkinter?

theteacher.info at gmail.com theteacher.info at gmail.com
Sat Aug 30 16:11:30 EDT 2014


Peter - Thanks! I've had a play around and followed your advice and have something that should take me on to the next step! This is what I have so far and it works, Thanks.

from tkinter import *
from tkinter import ttk
import random

root = Tk()
root.title("Messing about")

def next_image(): 
    myLabel.config(image=random.choice(monster_images)) 
    # tell tkinter to invoke next_image() again after 200 miliseconds 
    root.after(200, next_image) 

mainframe = ttk.Frame(root, padding="3 3 12 12", width="800", height="600", borderwidth="120", relief="sunken")
mainframe.grid(column=0, row=0, sticky=(N, W, E, S))
mainframe.columnconfigure(0, weight=1)
mainframe.rowconfigure(0, weight=1)

mon1 = PhotoImage(file="MonsterImages/Converted/py01.gif")
mon2 = PhotoImage(file="MonsterImages/Converted/py02.gif")
mon3 = PhotoImage(file="MonsterImages/Converted/py03.gif")

#A list of object pictures
monster_images = [mon1, mon2, mon3]

#Set up one label
myLabel=ttk.Label(mainframe, image=mon1)
myLabel.grid(column=1, row=1, sticky=W)


next_image()

root.mainloop()



More information about the Python-list mailing list