Python:onkeypress没有turtle窗口?
我现在的问题是,我想通过命令检测按键Python:onkeypress没有turtle窗口?,python,window,turtle-graphics,Python,Window,Turtle Graphics,我现在的问题是,我想通过命令检测按键 onkeypress(fun,"key") 但当我导入onkeypress并从turtle收听时,当我运行程序时,会弹出一个turtle窗口。你知道如何再次关闭它,或者如何不让它出现? 感谢您满怀希望地给出答案,抱歉我的英语不好(我是德国人,13岁)可能很难找到python方面的专家。但是,如果您不限于该库,则可以使用以下代码获取用户按下的键(上次调用实际上为您获取键): 代码来自 class _Getch: """Gets a single ch
onkeypress(fun,"key")
但当我导入onkeypress并从turtle收听时,当我运行程序时,会弹出一个turtle窗口。你知道如何再次关闭它,或者如何不让它出现?
感谢您满怀希望地给出答案,抱歉我的英语不好(我是德国人,13岁)可能很难找到python方面的专家。但是,如果您不限于该库,则可以使用以下代码获取用户按下的键(上次调用实际上为您获取键): 代码来自
class _Getch:
"""Gets a single character from standard input. Does not echo to the
screen."""
def __init__(self):
try:
self.impl = _GetchWindows()
except ImportError:
self.impl = _GetchUnix()
def __call__(self): return self.impl()
class _GetchUnix:
def __init__(self):
import tty, sys
def __call__(self):
import sys, tty, termios
fd = sys.stdin.fileno()
old_settings = termios.tcgetattr(fd)
try:
tty.setraw(sys.stdin.fileno())
ch = sys.stdin.read(1)
finally:
termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
return ch
class _GetchWindows:
def __init__(self):
import msvcrt
def __call__(self):
import msvcrt
return msvcrt.getch()
getch = _Getch()