Change event type of event for widgets or use the .trace_variable () method?

Is there a type of change event for data input inputs such as Entry, Text, Spinner, Checkbutton, Radiobutton? As a result of changing the value of the value, I mean the ability to detect when the value of the widget has changed due to keyboard activity or cutting / deleting / pasting (and editing the text Edit_undo / edit_redo)? I do not see such an event described in the documentation for the Tkinter event [1].

Is it a suitable technique to bind Tkinter variables to widget values ​​that I want to track and use these .trace_variable ('w', ...) methods to bind to value changes? This seems like the right approach, but I have not seen much use of trace_variable () in the source code of the Tkinter application, which I studied, which made me cautious in using this approach.

[1] http://infohost.nmt.edu/tcc/help/pubs/tkinter/events.html

+2
source share
1 answer

Different widgets require different solutions. For example, the test buttons and switches have a command parameter, and with the input widget you can use the built-in test functions.

For all widgets that can be bound to a variable, running a trace variable is a common solution. A text widget is one of the exceptions because you cannot bind it to a variable without much effort.

In the tcl / tk world, I bind all my widgets to one array (the tcl name for the hash map / dictionary), and then put one trace into the array. Unfortunately, tkinter does not directly support tcl arrays. However, support is somewhat hackable. For more information, see My answer to this question: How to run the code when the value of the Tkinter widget changes?

+2
source

All Articles