Hi everyone,

Can someone help with Michael's question?  Unfortunately, I can't answer
it at the moment.

Here it is below.  (I've stripped off the image attachment.)


---------- Forwarded message ----------
Date: Fri, 4 Aug 2006 09:32:48 -0700 (PDT)
From: Michael Cochez <[EMAIL PROTECTED]>
To: [EMAIL PROTECTED]
Subject: Multiple buttons, One callback

Hi Danny,
I've just been reading your reply on this subject at
http://mail.python.org/pipermail/tutor/2005-September/041358.html
about a year ago.
I need something like this but also something more:
I'm making an app with an interface that is going to
look like in the added image. The "=" buttons are
there to copy the contents of the previous lines to
the current line.
To make the buttons tried a lot of things but the
problem is: the number of buttons is always different
(one less as the number of day) so it can be none or
20 or something else. So i putted the creation in a
for loop.
But now the real problem: every button must have its
own callback(because the linenumber is different) So
my question is: how can I give each button its 'own'
callback while only having one (the callbacks are all
the same but with another value of linenumber. I added
a piece of the code to show what i mean.

michaelcochez,

PS:excuse me if my English isn't comprehensive, I'm
not a native English speaker (I speak Dutch at home)

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
datelist=["monday","tuesday","wednesday","Thursday"]

frame2widgets=[]#to stay having a reference to the widgets

def makeidentical(linenumber):

    print "the linenumber is: %d" % (linenumber)



def make_callback(n):

    def callback():

        return makeidentical(n)

    return callback



from Tkinter import *

root=Tk()

frame2=Frame(root)

frame2.pack(side=LEFT)





callbacks=[make_callback(i) for i in range (len(datelist))]



for day in datelist:

    aÚtelist.index(day)

    if a>0:#on every line exept the first

        identicalbutton=Button(frame2,text="=",commandÊllbacks[a]())

        identicalbutton.grid(row=a+2,column=3,sticky=W)#the numbers are correct this is only a piece of the code

        frame2widgets.append(identicalbutton)













root.mainloop()
_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to