[Tkinter-discuss] writing a function to create button

Ilknur Ozturk Ilknur.Ozturk at cabot.com.tr
Fri May 5 15:53:30 CEST 2006


Hi Michael,

Actually my aim is a little bit different. I put one of the buttons in
my code;

        button_name = "menu"
        self.menu = Button(self.mycontainer,
                             command=lambda
                             arg1=button_name:
                              self.writecommand(arg1) 
                             ) 
        self.menu.configure(text="menu")
        self.menu.grid(row=2, column=0)
        ch = "<m>"
        self.menu.bind(ch,
                       lambda
                       event, arg1=button_name:
                       self.writecommand(arg1)
                       )

This part repeatedly occurs in my code for different buttons, but those
buttons placed in a different frames (not each in one, group by group)

For each button, button_name, configuration and geometry are changing.
It can be divided 2 or more functions if it can be achieved in any way. 

Thanks,

ilknur


-----Original Message-----
From: tkinter-discuss-bounces at python.org
[mailto:tkinter-discuss-bounces at python.org] On Behalf Of Michael Lange
Sent: Friday, May 05, 2006 12:42 PM
To: tkinter-discuss at python.org
Subject: Re: [Tkinter-discuss] writing a function to create button

On Fri, 5 May 2006 11:04:20 +0300
"Ilknur Ozturk" <Ilknur.Ozturk at cabot.com.tr> wrote:

> Hi all,
> 
>  
> 
> I prepared a GUI which contains lots of buttons. Instead of defining
> each of them one by one, I want to write a function that gets the
> parameters and create a button.(Each one calls same function for
> buttonclick event) Is it possible? If it is, can you give me a simple
> example?
> 

Hi Ilknur,

maybe you mean something like

    buttons = []
    r = 0
    c = 0
    for i in range(100):
        b = Button(master, text=i, **kw)
        b.grid(row=r, column=c)
        buttons.append(b)
        c += 1
        if c > 10:
            c = 0
            r += 1

I hope this helps

Michael
_______________________________________________
Tkinter-discuss mailing list
Tkinter-discuss at python.org
http://mail.python.org/mailman/listinfo/tkinter-discuss

______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email 
______________________________________________________________________


**********************************************************************
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
the system manager.

This footnote also confirms that this email message has been swept by
MIMEsweeper for the presence of computer viruses.

www.mimesweeper.com
**********************************************************************


______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email 
______________________________________________________________________


More information about the Tkinter-discuss mailing list