在 Python Tkinter 中绑定 Ctrl (-) [英] Binding Ctrl (-) in Python Tkinter

查看:32
本文介绍了在 Python Tkinter 中绑定 Ctrl (-)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have an application with a Text widget, and I want my font to get smaller when the user presses the Control key and the minus key (-).

代码

self.bind_all("<Control-=>", self.increaseFont)

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

seems to work fine for getting the font to increase when the user presses the control key and the equals key, but the line

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

似乎不起作用.

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

When I try to run it, it gives me a runtime error:

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

推荐答案

试试 self.bind_all("", self.decreaseFont).

这篇关于在 Python Tkinter 中绑定 Ctrl (-)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆