Reputation: 60
Is there any way to detect selection in Entry widget in tkinter, like we get in Text widget txt.get(SEL_FIRST, SEL_LAST) and txt.tag_ranges("sel")
Upvotes: 1
Views: 730
Reputation: 3089
If you just want to check if the selection is present you can use Entry.select_present()
method which returns True
if the selection is present.
If you want to get the selection you can use Entry.selection_get()
Minimal example:
from tkinter import *
def selection_present():
print(entry.select_present())
if entry.select_present():
print(entry.selection_get())
root = Tk()
entry = Entry(root)
entry.pack()
Button(root, text="Check selection", command=selection_present).pack()
root.mainloop()
Upvotes: 2