TkInter callback - how to ?

Michael P. Reilly arcege at shore.net
Wed Jun 23 22:48:03 CEST 1999


bernard <bh at cellware.de> wrote:

: I have an array of buttons (a keypad) all using the same callback
: function - is there any way of finding out which button invoked
: the callback ? I suppose I am looking for a tcl/tk solution
: something like
:   -command "myCallback $thisButton"
: but tkInter only seems to provide
:   -command myCallback

: Any help welcome

for index in range(5):
  button = Button(None,
    text='%d' % index,
    command=lambda i=index: myCallback(i)
  )
  button.pack()

Generally it is easier to give it a bound method or other callable object
with the needed information.

  -Arcege





More information about the Python-list mailing list