Tkinter中“ <Control->”的实际键盘符号是什么

时间:2019-08-08 18:17:14

标签: python python-3.x tkinter

我正在尝试使用Python 3.7和Tkinter创建文本编辑器。我在键盘快捷键上遇到了麻烦。这是键盘快捷键的代码:

# Keyboard shortcuts
self.master.bind("<Control-o>", lambda key: self.open())
self.master.bind("<Control-O>", lambda key: self.open())
self.master.bind("<Control-s>", lambda key: self.save())
self.master.bind("<Control-S>", lambda key: self.save())
self.master.bind("<Control-Shift-s>", lambda key: self.saveas())
self.master.bind("<Control-Shift-S>", lambda key: self.saveas())
self.master.bind("<Control-q>", lambda key: self.quit())
self.master.bind("<Control-Q>", lambda key: self.quit())
self.master.bind("<Control-=>", lambda key: self.zoomIn())
self.master.bind("<Control-->", lambda key: self.zoomIn())

这是我运行它时收到的错误:

Traceback (most recent call last):
  File "#############################################\TextPY\textpy.py", line 123, in <module>
    app = Application(master=root)
  File "#############################################\TextPY\textpy.py", line 27, in __init__
    self.master.bind("<Control-->", lambda key: self.zoomIn)
  File "C:\Python37\lib\tkinter\__init__.py", line 1251, in bind
    return self._bind(('bind', self._w), sequence, func, add)
  File "C:\Python37\lib\tkinter\__init__.py", line 1206, in _bind
    self.tk.call(what + (sequence, cmd))
_tkinter.TclError: no event type or button # or keysym

1 个答案:

答案 0 :(得分:1)

此行中有错误

self.master.bind("<Control-->", lambda key: self.zoomIn())

应该是

self.master.bind("<Control-minus>", lambda key: self.zoomIn())