首页 > 解决方案 > 如何在屏幕上重复一个程序点击

问题描述

嗨,我一直在尝试让我的程序在单击时重复/重新启动,这会得到一些帮助,我不知道该怎么做

import turtle
import time
import random
from random import randint
from time import sleep
wn = turtle.Screen()
wn.title("Reaction test")
wn.setup(width=600,  height=600 )
wn.tracer(0)
wn.bgcolor("blue")
turtle.write("Click to start", move=False, align="center", font=("Arial", 40, "normal"))
from turtle import *
start = time.perf_counter()
def clicked(x, y):
    resetscreen()
    turtle.hideturtle()
    wn.setup(width=600, height=600)
    wn.tracer(0)
    wn.bgcolor("red")
    wn.title("Reaction test")
    turtle.write("   Click when the\nscreen turns green", move=False, align="center", font=("Arial", 40, "normal"))
    sleep(randint(2, 10))
    resetscreen()
    turtle.hideturtle()
    wn.setup(width=600, height=600)
    wn.tracer(0)
    wn.bgcolor("green")
    wn.title("Reaction test")
    turtle.write("CLICK!", move=False, align="center", font=("Arial", 40, "normal"))
    start
    wn.onscreenclick(click)
wn.listen()
wn.onscreenclick(clicked)
def click(x, y):
    ms = time.perf_counter() - start
    resetscreen()
    turtle.hideturtle()
    wn.setup(width=600, height=600)
    wn.tracer(0)
    wn.bgcolor("Green")
    wn.title("Reaction test")
    md = (ms*100/2)
    milliseconds = round(md)
    turtle.write((f"Your reaction time was\n    {milliseconds} milliseconds"), move=False, align="center", font=("Arial", 40, "normal"))
wn.mainloop()

标签: pythonturtle-graphics

解决方案


你可以做:

def reset():
   screen.reset()
turtle.onclick(reset)

这应该工作


推荐阅读