python⼀个按钮控制两个事件_PythonTurtle按键事件不重复是有办法让它在Windows上⼯作,让拿着钥匙 下创建重复的事件?
按键重复是操作系统功能,不同的系统处理它的⽅式不同。例如,默认情况下,我的Apple OS X系统上的按键会重复播放,但我可以进⼊系统偏好设置/键盘并更改速率,甚⾄关闭它(我试图测试以下代码。)
如果您不喜欢“T有键重复,想模拟它,下⾯是⼀个使⽤龟定时器事件⼀键启动的关键重复下来,把它关掉关键了⼀个简单的例⼦:
# import the turtle module so we can u all the neat code it contains
from turtle import Turtle, Screen
KEY_REPEAT_RATE = 20 # in milliconds
# Create a variable `tina` that is a Turtle() object. Set shape to 'turtle'
tina = Turtle('turtle')
# Create a variable `screen`, a Screen() object, that will handle keys
screen = Screen()
# Define functions for each arrow key
def go_left():
tina.left(7)
if repeating:
def go_right():
tina.right(7)
if repeating:
def go_forward():
tina.forward(10)
if repeating:
exerci用法
bookcadef go_backward():
tina.backward(10)
英语四级答案包过if repeating:
def start_repeat(func):
punto
global repeating
repeating = True
func()alloys
def stop_repeat():
googlerglobal repeating
repeating = Falduring怎么读
repeating = Fal
# Tell the program which functions go with which keys
序言英文>架子英文
# Tell the screen to listen for key press
screen.listen()
when和while的区别screen.mainloop()
然⽽,你的挑战是当你需要这个模拟重复时,以及当系统已经具有重复能⼒时 - 弄清楚这两种情况都会变得混乱。