python - cmd + a not working in tkinter entry -


i've being building basic ui using tkinter, , noticed cmd + a (or select command) not enabled.

how enable shortcuts in tkinter entry text field.

this code :

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

@goyo answered question. want share contribution not see interest in selecting text of entry widget's text , not doing else it. going provide dirty mcve show how going use selected text: a) either delete or b) copy it.

for a), following function job:

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

it work under condition bind corresponding events described function's name entry widget:

entry.bind('<control-a>', select_text_or_select_and_copy_text) entry.bind('<control-c>', select_text_or_select_and_copy_text)  

for b), can use function:

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

and bind delete event entry widget:

entry.bind('<delete>', delete_text) 

i tried mcve on ubuntu , works:

import tkinter tk import tkinter.ttk 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() 

Comments

Popular posts from this blog

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -