python - cmd + a 在 tkinter 条目中不起作用

标签 python tkinter

我正在使用 Tkinter 构建一个基本的 UI,我注意到 cmd + a(或选择所有命令)未启用。

如何启用 tkinter 中的所有快捷方式,尤其是输入文本字段。

这是我的代码:

entry1 = ttk.Entry(root, width = 60)
entry1.pack()

最佳答案

如果 tkinter 没有定义您想要的快捷方式,您可以通过绑定(bind)键盘事件来定义自己的快捷方式。

import tkinter as tk
import tkinter.ttk as ttk

def callback(ev):
    ev.widget.select_range(0, 'end') 

root = tk.Tk()
entry = ttk.Entry(root)
entry.pack()
entry.bind('<Command-a>', callback)
root.mainloop()

我认为 Command 是 cmd 键的正确前缀,但我没有要测试的 mac。在 Windows 中,它绑定(bind)到控制键。

关于python - cmd + a 在 tkinter 条目中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45301245/

相关文章:

python - 制作一个等待参数更改的函数,由按钮触发

python - Tkinter:列表框分隔符、禁用项、键盘导航?

python - 有没有办法查看给定 CL 提交到哪个流

python - 将包含 GEOMETRY 列的表加载到 Pandas DataFrame

python - 将 Vim 连接到 Python REPL session

python - 如何在 Tensorflow 中仅使用 Python 制作自定义激活函数?

python - django 无法在基于类的 View 中使用全局变量

python - tkinter - 为什么会有像 bbox 这样的东西?

python - 当列表索引不能超出范围时,为什么会出现 IndexError : list index out of range. ?

python - 将 IDLE 集成到 Tkinter 程序中