I am trying to make a small dice roll program. By using after(), I would like to make a small "image animation". that displays an other image every ... ms. Unfortunatly sofar only the final image(of the dice roll outcome) is shown and not the visual animation.

Does any one have an idea, what I might be doing wrong?

Thank you!

Inline Code Example Here

from random import randint
from tkinter import *

def dicenumb():

    global imagex
    numb = randint(1,6)

    a="dice1.gif"
    b="dice2.gif"
    c="dice3.gif"
    d="dice4.gif"
    e="dice5.gif"
    f="dice6.gif"
    g="dice{}.gif".format(str(numb))

    image_list = [f,b,a,c,f,e,d,c,a,b,c,f,e,a,b,c,a,b,d,e,f,e,a,c,g]

    for img in image_list:
        imagex = PhotoImage(file=img)
        canvas.itemconfig(i, image=imagex)
        canvas.after(50)

root = Tk()
upFrame = Frame(root, width=400, height=400)
upFrame.pack(side=TOP)
downFrame = Frame(root, width=400, height=300)
downFrame.pack(side=BOTTOM)

canvas=Canvas(upFrame, width=200, height=200)

canvas.pack()

i=canvas.create_image(1,1, anchor=NW, image="")

button1 = Button(downFrame, text="Roll", command=dicenumb)
button1.pack(side=TOP)

root.mainloop()

just added,

root.update()

to the loop, it works now

Thanks for letting us know.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.