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

html - How to set bootstrap input responsive width? -

javascript - Highchart x and y axes data from json -

javascript - Get js console.log as python variable in QWebView pyqt -