why do i have to disable the list of widgets in tkinter canvas?

I ended up having to move the while loop outside the function and adding root.update_idletasks() and root.update() instead of having root.mainloop(). From this post I learned that your program will basically stop at mainloop while update will allow the program to continue. This is what I ended up with:

def add_coordinates(index):
    x, y, z = database[index]
    coordinates.append(x)  # coordinates is an empty list
    coordinates.append(y)
ind = 0 # ind means index
while ind < len(database):
    if ind < 2:
        add_coordinates(ind)
    elif ind == 2:
        trajectory = canvas.create_line(coordinates, smooth="true")
        add_coordinates(ind)
        canvas.after(1000)
    elif ind > 2:
        add_coordinates(ind)
        canvas.after(1000, canvas.coords(trajectory, coordinates))
    else:
        pass
    ind += 1
    root.update_idletasks()
    root.update()

Of course, I have things like import statements at the beginning and root.mainloop() at the very end of the file.

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top