Skip to content
Advertisement

Determine which widget triggers the callback function in command

I am coding a GUI in python using tkinter. I assgined the same callback function to the “command” argument in 3 buttons. The purpose of these buttons is to specify a directory depending on the widget name. Is there any way that I can tell which widget triggered the callback function, and assign directory in the callback accordingly?

(of course, I can create different callback functions and assign to each individual widgets, but I wanna adopt a slick approach.)

Thx in advance!

Advertisement

Answer

(Shamelessly copied from Tkinter Callbacks.)
You could try something like:

JavaScript

If you want the Button instance as a callback argument you can do something like:

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