I'm trying to make a script with tkinter that displays some elements one after each other (not all of them at the same time) using .after().
The problem I have is that all elements are displayed at the same time after the overall waiting time has finished (overall waiting time = sum of the individual time of each element).
I've checked many examples on the web, and I guess I'm using the .after() method wrong, but I just can't figure out why.
I would expect the following code to update the label wait for 0.5 seconds after each loop. Nonetheless, what I get is a total wait of 3 seconds, after which the tkinter window appears, showing the last element of the list.
import tkinter as tk
import random
grid = [1, 2, 3, 4, 5, 6]
root = tk.Tk()
canvas = tk.Canvas(root, width=200, height=200)
canvas.pack()
def refresh():
for i in range(len(grid)):
text = grid[i]
label.configure(text=text)
root.after(500)
label = tk.Label(canvas, text='0', font='Courier 18')
label.place(relx=0.45, rely=0.4)
refresh()
root.mainloop()
Thanks in advance!