python中delay__Python time delay

  • Post author:
  • Post category:python


问题

Alright, I want to know how to delay a portion of a program without pausing the entire program.

I’m not necessarily good at python so if you could give me a relatively simple answer if possible, that would be great.

I want to have a turtle draw a circle on screen every time this function is called, this is what I have:

import time

from random import randint

turtle5 = turtle.Turtle()

coinx = randint(-200, 200)

coiny = randint(-200, 200)

turtle5.pu()

turtle5.goto(coinx, coiny)

turtle5.pd()

turtle5.begin_fill()

turtle5.fillcolor(“Gold”)

turtle5.circle(5, 360, 8)

turtle5.end_fill()

time.sleep(1)

turtle5.clear()

回答1:

There is turtle.ontimer() that calls a function with the specified delay:

turtle.ontimer(your_function, delay_in_milliseconds)

回答



版权声明:本文为weixin_42134144原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。