Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/280.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python:onkeypress没有turtle窗口?_Python_Window_Turtle Graphics - Fatal编程技术网

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()