Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/325.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/18.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 tkinter不工作的按键符号(“输入”和“退出”)_Python_Python 3.x_Events_Turtle Graphics - Fatal编程技术网

Python tkinter不工作的按键符号(“输入”和“退出”)

Python tkinter不工作的按键符号(“输入”和“退出”),python,python-3.x,events,turtle-graphics,Python,Python 3.x,Events,Turtle Graphics,我在tkinter上得到了坏的kysym进入和逃跑。enter的想法是,当用户按下enter键时,它会在python程序中创建一个新行,当用户按下escape键时,它会关闭程序。我的代码是否弄乱了什么 以下是错误: Traceback (most recent call last): File "C:\Users\User\Desktop\python\turtle\helloworld.py", line 166, in <module> onkey(bye, "KP_

我在tkinter上得到了坏的kysym进入和逃跑。enter的想法是,当用户按下enter键时,它会在python程序中创建一个新行,当用户按下escape键时,它会关闭程序。我的代码是否弄乱了什么

以下是错误:

Traceback (most recent call last):
  File "C:\Users\User\Desktop\python\turtle\helloworld.py", line 166, in <module>
    onkey(bye, "KP_Escape")
  File "<string>", line 1, in onkey
  File "C:\Python32\lib\turtle.py", line 1393, in onkey
    self._onkeyrelease(fun, key)
  File "C:\Python32\lib\turtle.py", line 687, in _onkeyrelease
    self.cv.bind("<KeyRelease-%s>" % key, eventfun)
  File "C:\Python32\lib\turtle.py", line 416, in bind
    self._canvas.bind(*args, **kwargs)
  File "C:\Python32\lib\tkinter\__init__.py", line 977, in bind
    return self._bind(('bind', self._w), sequence, func, add)
  File "C:\Python32\lib\tkinter\__init__.py", line 932, in _bind
    self.tk.call(what + (sequence, cmd))
_tkinter.TclError: bad event type or keysym "KP_Escape"
而不是:

onkey(draw_newline, "KP_Enter")
onkey(bye, "KP_Escape")
做:

这个案子很重要。Turtle将在将这些键名发送到tkinter之前,用适当的Tk语法包装它们

onkey(draw_newline, "KP_Enter")
onkey(bye, "KP_Escape")
onkey(draw_newline, "Return")
onkey(bye, "Escape")