0

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()

Edited by Igor_1

2
Contributors
2
Replies
17
Views
2 Years
Discussion Span
Last Post by vegaseat
2

just added,

root.update()

to the loop, it works now

Edited by Igor_1

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.