How I do an animation that works with a set timer in python?
Question: I am trying to do some animation that works with the timer. When the time
finishes, the animation should finish at the same time. I was thinking on
doing something like a battery bar in a cell phone. That's why I have a green
rectangle in another window, but I don't know how to do for the green get
black or the rectangle empty slowly with the timer. If you have another
suggestion for animation you can do it. Thanks

* * *
    
    
    from tkinter import *
    import math
    import time
    
    aux=False
    segundo=60
    
    Ventana1 = Tk()
    Ventana1.title("Timer")
    Ventana1.geometry("500x350+100+100")
    
    def paso():
        global aux
        global segundo
    
        if aux:
            segundo -= 1
            tiempo["text"] = segundo
            tiempo.after(1000, paso)
    
        if segundo==0:
           aux=False
           tiempo.configure(text=segundo, fg="blue")
    
        if segundo<21:
           tiempo.configure(text=segundo, fg="red")
    
    def inicio ():
        global aux
        global segundo
    
        segundo=segundo
        if aux:
            pass
    
        else:
            aux=True
            paso()
            tiempo.configure(text=segundo, fg="blue")
    
    def pausa ():
        global aux, segundo
    
        aux=False
        tiempo.configure(text=segundo, fg="blue")
    
    def reset ():
        global aux
        global segundo
    
        segundo=int(Entry.get(Segunditos)) + 60*int(Entry.get(Minuticos))
        aux=False
        tiempo["text"] = segundo
        tiempo.configure(text=segundo, fg="blue")
    
    tiempo = Label(Ventana1, text=segundo, font=("calibri", 200))
    tiempo.pack()
    
    Button(Ventana1, text="Arranquelo", command= inicio).place(x=120, y=220)#Button start
    Button(Ventana1, text= "Parelo", command= pausa).place(x=200, y=220)#button pause
    Button(Ventana1, text= "Acabelo", command= reset).place(x=300, y=220)#button reset
    
    MinAviso=Label(Ventana1, text="Minutos").place(x=125, y=260)
    SegAviso=Label(Ventana1, text="Segundos").place(x=305, y=260)
    
    Minuticos=Entry(Ventana1)
    Minuticos.place(x=70, y=290)
    
    Segunditos=Entry(Ventana1)
    Segunditos.place(x=250, y=290)
    
    from tkinter import *
    
    Ventana2 = Tk()
    
    Canvas = Canvas(Ventana2, width=2000, height=1500)
    Canvas.pack()
    Canvas.create_rectangle(200, 200, 1000, 300, fill="green")
    
    mainloop()
    
    #Ventana1.mainloop()
    


Answer: The biggest problem is that you are creating two instances of `Tk`. Tkinter
isn't designed to work that way. If you want a floating window, create
instances of `Toplevel`.

Next, you need to save a reference to the rectangle you are drawing on the
canvas.

    
    
    Canvas = Canvas(Ventana2, ...)
    rect = Canvas.create_rectangle(...)
    

As your timer runs, you can modify the object using that reference.

    
    
    def paso():
        ...
        if aux:
            ...
            Canvas.itemconfigure(rect, ...)
    

