[Tkinter-discuss] Recognizing buttons

Michael O'Donnell michael.odonnell at uam.es
Sun Aug 15 10:08:16 CEST 2010

Hi Guido,

> Is it possible to have a set of buttons, all calling to the same function, recognize which of the buttons was the one that call the function?

 One solution to your problem, using lambda to define the function call.

from Tkinter import *

def killBut(but):

tk = Tk()

but1=Button(tk, text="B1")
but1['command']=lambda b=but1: killBut(b)

but2=Button(tk, text="B2")
but2['command']=lambda b=but2: killBut(b)


On Sun, Aug 15, 2010 at 4:06 AM, Guido Carballo-Guerrero <charras at me.com> wrote:
> Hello;

> 'Cause what I want to do, is create a set of buttons, where I will not know how many buttons will be created, that will depend on the input of the user. Once the user have this, he will click one of those buttons, and depending on which button was press, the program will erase that part of the input that the operator gave.
> Regards!
> Guido Carballo
> _______________________________________________
> Tkinter-discuss mailing list
> Tkinter-discuss at python.org
> http://mail.python.org/mailman/listinfo/tkinter-discuss

More information about the Tkinter-discuss mailing list