+ 1
I would like for my code to pause between each line of text.
Hello! In my code, I have alot of text, and I would like to make it puase between them all. I have tried import time time.sleep(1) but it has not worked. If anyone has any information, I would really appreciate it! Thankyou once again, Poppy
4 Réponses
+ 4
Try the sleep function in the time module.
import time time.sleep(60)
And put this in a while loop and a statement will only execute on the minute... That allows you to run a statement at predefined intervals regardless of how long the command takes (as long as it takes less than a minute or 5 or 60 or whatever you set it to) For example, I wanted to run a ping once a minute. If I just time.sleep(60) or time.sleep(45)even, the ping will not always take the same amount of time. Here's the code :)
time.sleep(time.localtime(time.time())[5])
The [5] just pulls the seconds out of the time.localtime()'s return value.
The great thing about time.sleep is that it supports floating point numbers!
import time time.sleep(0.1)
or try to do like this
>>> import time
>>> import sys
>>> blah = "This is written slowly\n"
>>> for l in blah:
... sys.stdout.write(l)
... sys.stdout.flush()
... time.sleep(0.2)
...
This is written slowly
+ 2
if you are using Tkinter dont forget to put Tk.update() afer each time.sleep()
+ 1
Thankyou!!
0
maybe 1 millisecond too fast for hold ?
try 100 or 1000 instead !?