How I can select all text like block using click+drug left mouse in Entry widget tkinter python.
e1 = tk.Entry(bop, width = 50, font = "Helvetica 13")
e1.grid(row=1,column=1, padx=15, pady=15)
e1.bind_class("Entry","<Control-a>", select_all(e1))
here is the function of select_all()
:
def select_all(e):
a = e.select_range(0,tk.END)
There was so many similar examples on SO
bind
expects filename without()
and arguments (callback). But alsobind
executes this function always with one argumentevent
which gives access to entry which executed this functionevent.widget
so you can use it with many different entries. And finallyEntry
has.get()
to get all text.EDIT:
Because after releasing keys
<Control-a>
selection is removed so I useafter()
to execute selection after 50ms. It selects all text (but it moves cursor to the beginning) and moves cursor to the end. (see code above)EDIT:
Before I couldn't find correct combination with
Release
but it has to be<Control-KeyRelease-a>
and now it doesn't needafter()