[Tkinter-discuss] command for dynamic buttons

boivie boivie at hotmail.com
Fri Aug 7 23:34:58 CEST 2009


I'm making an application with lots of similar buttons. But I can't figure
out how to make the command unique for each button.

I tried to follow the advice in 
http://mail.python.org/pipermail/python-list/2002-July/152242.html this  old
message, but every button still gives the same output.

class Program:
    def __init__(self, ruta):

        bokst = ['а', 'б', 'в', 'г', 'д', 'е', 'ё', 'ж', 'з', 'и', 'й', 'к']

        i = 1
        for option in bokst:
            laddaKnapp = lambda index=0, obj=self: obj.tryck(option) 
            knapp = Button(self.nere, text=str(option), command=laddaKnapp)
            knapp.grid(row=1, column=i)
            i = i + 1

    def tryck(self, bokstav):

I found how to do it in pygtk in 
http://www.pygtk.org/pygtk2tutorial/examples/clipboard.py this example , but
I've not been able to find a singel example of dynamic buttons in tkinter.
View this message in context: http://www.nabble.com/command-for-dynamic-buttons-tp24872360p24872360.html
Sent from the Python - tkinter-discuss mailing list archive at Nabble.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tkinter-discuss/attachments/20090807/5b52d38d/attachment.htm>

More information about the Tkinter-discuss mailing list