Skip to content
Advertisement

How do you update a label every time text is typed into a textbox, using tkinter

I’m trying to create an app where a part of it involves a label that dynamically changes and displays the number of characters typed within the textbox every time it gets updated. I couldn’t find any information regarding this and unsure whether this is even possible.

Advertisement

Answer

If you want a simpler solution that requires a bit more work by the caller, look at this:

JavaScript

This basically binds all keyboard presses to the callback function. I can’t think of any way to change the text in a text widget without pressing a keyboard button.

Please note that it will only run when a key is pressed so it wouldn’t work if you called text_widget.insert or text_widget.delete (@acw1668 found that problem). It is the caller’s responsibility to call _callback just after they call .insert/.delete.

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