如何添加多个键来监听 python 乌龟?
How can I add multiple keys to listen in python turtle?
我想在 python 乌龟中放置更多键,但每次我这样做时它都会告诉我一个错误。有什么办法可以用多个键来完成吗?
代码:
screen.listen()
screen.onkey(tic.one, "1")
screen.onkey(tic.two, "2")
screen.onkey(tic.three, "3")
我要的代码:
screen.listen()
screen.onkey(tic.one, "1, t")
screen.onkey(tic.two, "2, s")
screen.onkey(tic.three, "3, k")
你可以这样做:
screen.onkey(tic.one, "1")
screen.onkey(tic.one, "t")
screen.onkey(tic.two, "2")
screen.onkey(tic.two, "s")
screen.onkey(tic.three, "3")
screen.onkey(tic.three, "k")
screen.listen()
或者遍历各种可能性,例如:
key_handlers = [(tic.one, "1t"), (tic.two, "2s"), (tic.three, "3k")]
for handler, keys in key_handlers:
for key in keys:
screen.onkey(handler, key)
screen.listen()
我想在 python 乌龟中放置更多键,但每次我这样做时它都会告诉我一个错误。有什么办法可以用多个键来完成吗? 代码:
screen.listen()
screen.onkey(tic.one, "1")
screen.onkey(tic.two, "2")
screen.onkey(tic.three, "3")
我要的代码:
screen.listen()
screen.onkey(tic.one, "1, t")
screen.onkey(tic.two, "2, s")
screen.onkey(tic.three, "3, k")
你可以这样做:
screen.onkey(tic.one, "1")
screen.onkey(tic.one, "t")
screen.onkey(tic.two, "2")
screen.onkey(tic.two, "s")
screen.onkey(tic.three, "3")
screen.onkey(tic.three, "k")
screen.listen()
或者遍历各种可能性,例如:
key_handlers = [(tic.one, "1t"), (tic.two, "2s"), (tic.three, "3k")]
for handler, keys in key_handlers:
for key in keys:
screen.onkey(handler, key)
screen.listen()