enkiv2
enkiv2

Reputation: 306

Bind callback to selection change on Tkinter Text widget

I'm looking for a way to call a callback function whenever the contents of the SEL tag on Tkinter's Text widget changes, other than enumerating all of the possible ways that selections could change and checking on each of them. Is there a mechanism for doing this? Or, do I need to essentially add a binding for every Button1-Release and Key-Release-Shift that checks for changes to SEL?

Upvotes: 0

Views: 720

Answers (1)

patthoyts
patthoyts

Reputation: 33223

According to the manual (in the section "The Selection"):

Whenever the sel tag range changes a virtual event <<Selection>> is generated.

so binding the widget for this event should do this for you.

I know you tagged the question for python use, but it is well worth checking the Tk documentation for the details on using the Tk widgets.

Upvotes: 3

Related Questions