我正在使用 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/