python - <Command-a> for Text - Tkinter -
i found below code :
def callback(ev): ev.widget.select_range(0, 'end') root = tk() t = text(root, height=10, width=40) t.pack() t.bind('<command-a>', callback) //works entry root.mainloop() i'm trying make cmd + a or ctrl + a (windows) work text in tkinter.
error (when give command : cmd-a in text):
'text' object has no attribute 'select_range'
the code ok except inventing methods on text widget. however, if @ bindings on widget class (text) there virtual events defined
>>> '<<selectall>>' in root.bind_class('text') true so in handler keyboard event, use event_generate raise selectall virtual event.
import tkinter tk def select_all(ev): ev.widget.event_generate('<<selectall>>') root = tk.tk() txt = tk.text(root) txt.pack() txt.bind('<control-a>', select_all)
Comments
Post a Comment