Unable to draw a line slowly using Python tkinter

13 views
Skip to first unread message

mukund athavale

unread,
Jan 12, 2021, 9:36:21 PM1/12/21
to spyder
Hi,

I want to draw a line on screen so that it gets displayed slowly from left to right.
The line is not drawn point by point after the sleep time interval. The line appears suddenly after the total time elapsed.

Increasing sleep time does not help. I have also tried the "after" command but does not help.

Is there any simple solution ?

I have used following code.

# my code
import time
from tkinter import *
mywindow = Tk()

mywindow.minsize( width=600,height=600)
mycanvas = Canvas(mywindow, width=500, height=500, background = "yellow")
mycanvas.place(x=50, y = 0)

startx = 1

for i in range (1,500,10):
    mycanvas.create_line(startx,100,i,100 )
    startx = i
    time.sleep(0.010)

mc.mainloop()

Mukund Athavale
Mumbai, India

paul kairis

unread,
Jan 12, 2021, 10:29:04 PM1/12/21
to spyd...@googlegroups.com
I'm using Spyder 3.2.6 ... added mywindow.update() inside the loop

# my code
import tkinter as tk
import time

mywindow = tk.Tk()
mywindow.minsize(width=600,height=600)

mycanvas = tk.Canvas(mywindow, width=500, height=500, background = "yellow")

mycanvas.place(x=50, y = 0)

startx = 1

for i in range (1,500,10):
    mycanvas.create_line(startx,100,i,100 )
    startx = i
    time.sleep(0.010)
    mywindow.update()

tk.mainloop()



--
You received this message because you are subscribed to the Google Groups "spyder" group.
To unsubscribe from this group and stop receiving emails from it, send an email to spyderlib+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/spyderlib/443ef185-536e-4f4d-8029-a112ba4007abn%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages