Skip to content
Advertisement

Python: Tkinter bind(“<>”) works only once

so i was trying out tkinter Text widget.. and made a small code that highlights the word “print” in the text.. CODE:

JavaScript

In this, the root.bind('<<Modified>>', get) works only once. i checked it with the line print("Highlighting...") it just worked once even when i enter thousands of characters..

Am i doing something wrong? or my approach is bad?

JavaScript

Advertisement

Answer

Try this:

JavaScript

This uses the CustomText that @BryanOakley created here.

Also I had to remove the break from the end of your while True loop because it stopped searching for "print".

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement