在 Python Tkinter 中绑定 Ctrl (-)

mat*_*ots 2 python tkinter

我有一个带有文本小部件的应用程序,我希望当用户按下 Control 键和减号键 (-) 时我的字体变小。

编码

self.bind_all("<Control-=>", self.increaseFont)
Run Code Online (Sandbox Code Playgroud)

当用户按下控制键和等号键时,似乎可以很好地使字体增加,但行

self.bind_all("<Control-->", self.decreaseFont)
Run Code Online (Sandbox Code Playgroud)

似乎不起作用。

当我尝试运行它时,它给了我一个运行时错误:

Traceback (most recent call last):
  File "./mathEditor.py", line 122, in <module>
    app = MathEditor(fileName = sys.argv[1])
  File "./mathEditor.py", line 40, in __init__
    self.bind_all("<Control-->", self.decreaseFont)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk/Tkinter.py", line 997, in bind_all
    return self._bind(('bind', 'all'), sequence, func, add, 0)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk/Tkinter.py", line 940, in _bind
    self.tk.call(what + (sequence, cmd))
_tkinter.TclError: no event type or button # or keysym
Run Code Online (Sandbox Code Playgroud)

nne*_*neo 6

试试self.bind_all("<Control-minus>", self.decreaseFont)