Answer the question
In order to leave comments, you need to log in
The question is, why does the python in the While loop not draw objects?
task: to implement the animation of moving the circle.
from tkinter import *
import time
root = Tk()
canvas = Canvas(root,width=1000,height=500)
x=0
y=0
canvas.create_oval(x,y,x+10,y+10)
start_time = time.time()
sec = 10
while (time.time()-start_time) <= sec:
canvas.delete('all')
x=20*(time.time()-start_time)
y=30*(time.time()-start_time)
canvas.create_oval(x,y,x+10,y+10)
canvas.pack()
root.mainloop()
Answer the question
In order to leave comments, you need to log in
Because the processing of all events in a window application, including window redrawing, occurs in the event loop. You "stop" it with your cycle.
Try adding a canvas update canvas.update()
from tkinter import *
import time
root = Tk()
canvas = Canvas(root,width=1000,height=500)
x=0
y=0
canvas.create_oval(x,y,x+ 10,y+10)
canvas.pack()
start_time = time.time()
sec = 10
while (time.time()-start_time) <= sec:
canvas.delete('all')
x=20*(time. time()-start_time)
y=30*(time.time()-start_time)
canvas.create_oval(x,y,x+10,y+10)
canvas.update()
root.mainloop()
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question