How to return instance of button pressed in Python-based TKinter -


i trying access label of button in tkinter, when button pressed. involves returning reference target button pressed.

currently, have input arguments, done binding command option lambda function i.e.

button['command'] = lambda: fun_to_call(arg) 

is there way return instance? have checked tkdocs , not cover. also, have tried using separate list of strings instead label. however, returns last element of list (i believe due lambda function not binding specific element list when creating button instance. have used list generate list of buttons.)

in short, event-based function bound button returns parent (the button being pressed).

def add_callback(control, fun):     def inner():         return fun(control)     control['command'] = inner  ...  def test_callback(button):     print "button instance:", button  b = button(text="click me") add_callback(b, test_callback) 

more declarative:

def with_callback(control, fun):     def inner():         return fun(control)     control['command'] = inner     return control  ... b = with_callback(button(text="click me"), test_callback) 

Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -