Python cmd+;a在tkinter条目中不工作

Python cmd+;a在tkinter条目中不工作,python,tkinter,Python,Tkinter,我正在使用Tkinter构建一个基本的UI,我注意到cmd+a(或Select all命令)没有启用 如何启用tkinter中的所有快捷方式,尤其是输入文本字段 这是我的代码: entry1 = ttk.Entry(root, width = 60) entry1.pack() 如果tkinter没有定义您想要的shorcuts,您可以通过绑定键盘事件来定义自己的shorcuts import tkinter as tk import tkinter.ttk as ttk def callb

我正在使用Tkinter构建一个基本的UI,我注意到cmd+a(或Select all命令)没有启用

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

这是我的代码:

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

如果tkinter没有定义您想要的shorcuts,您可以通过绑定键盘事件来定义自己的shorcuts

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()
将tkinter作为tk导入
将tkinter.ttk导入为ttk
def回调(ev):
ev.widget.选择_范围(0,“结束”)
root=tk.tk()
entry=ttk.entry(根)
entry.pack()
entry.bind(“”,回调)
root.mainloop()

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

@Goyo已经回答了您的问题。我想分享我的贡献,因为我看不出有兴趣选择条目小部件文本的文本,也不想用它做任何其他事情。因此,我将向您提供一个脏MCVE,以显示如何使用所选文本:a)您将删除它或b)您将复制它

对于a),以下功能将完成此工作:

def select_text_or_select_and_copy_text(e):
    e.widget.select_range(0, 'end') 
它将在以下条件下工作:将函数名称描述的相应事件绑定到条目小部件:

entry.bind('<Control-a>', select_text_or_select_and_copy_text)
entry.bind('<Control-c>', select_text_or_select_and_copy_text) 
entry.bind('<Delete>', delete_text)
并将
Delete
事件绑定到条目小部件:

entry.bind('<Control-a>', select_text_or_select_and_copy_text)
entry.bind('<Control-c>', select_text_or_select_and_copy_text) 
entry.bind('<Delete>', delete_text)
entry.bind(“”,删除\u文本)
我在Ubuntu上试用了这个MCVE,它可以工作:

import tkinter as tk
import tkinter.ttk as ttk


def select_text_or_select_and_copy_text(e):
    e.widget.select_range(0, 'end')     

def delete_text(e):
    e.widget.delete('0', 'end')


root = tk.Tk()

entry = ttk.Entry(root)
entry.pack()

entry.bind('<Control-a>', select_text_or_select_and_copy_text)
entry.bind('<Control-c>', select_text_or_select_and_copy_text)
entry.bind('<Delete>', delete_text)

root.mainloop()
将tkinter作为tk导入
将tkinter.ttk导入为ttk
def选择文本或选择并复制文本(e):
e、 小部件。选择_范围(0,'结束')
def删除_文本(e):
e、 widget.delete('0','end')
root=tk.tk()
entry=ttk.entry(根)
entry.pack()
条目.绑定(“”,选择文本或选择并复制文本)
条目.绑定(“”,选择文本或选择并复制文本)
条目.绑定(“”,删除\u文本)
root.mainloop()

而不是
(在Ubuntu上测试)@billabegueradj我猜cmd+a是mac的
在Windows中的工作方式似乎相同,但我不确定它在mac中是如何工作的。互联网站中的建议建议使用