On this page describing the Tkinter text widget, it's stated that 'The selection is a special tag named SEL (or “sel”) that corresponds to the current selection. You can use the constants SEL_FIRST and SEL_LAST to refer to the selection. If there’s no selection, Tkinter raises a TclError exception.'
My question: is there a more efficient way to tell if there is a selection in a Text widget besides fooling with exceptions, like the below code?
seltext = None
try:
seltext = txt.get(SEL_FIRST, SEL_LAST)
except TclError:
pass
if seltext:
# do something with text