python - 如何在屏幕上重复一个程序点击
问题描述
嗨,我一直在尝试让我的程序在单击时重复/重新启动,这会得到一些帮助,我不知道该怎么做
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()
解决方案
你可以做:
def reset():
screen.reset()
turtle.onclick(reset)
这应该工作
推荐阅读
- java - 如何从字符串图像中获取像素 RGB 值?.get 不适用于 imageLoader(处理中)
- swift - 在这种情况下,“Promise”对于类型查找是模棱两可的
- php - 如何添加具有不同whenLoaded关系的相同数组键?
- google-visualization - 更改 TreeMap 的选择事件侦听器
- c# - Quartz.net 3.0.6 和 system.data.sqlite 1.0.109,没有提供者“SQLite-10”的元数据信息
- java - 合并排序返回由第一个条目的多个重复项组成的 ArrayList,而不是排序的 ArrayList
- java - 在列表中查找增量之前的最小值(并更新它)
- micronaut - Micronaut 控制器中的默认处理程序
- java - 如何在 Java 中合并两个对象?
- c++ - 在 C++ 中创建一个多位数字