I’m trying to execute different code for each tkinter button – the names of which are not know until called from a list. gtk has get label (unfortunately I can’t use gtk).
How might I implement similar with tkinter?
def click_one(newbuttonname):
try:
writethisdown = open("participantsmovedlog.txt", 'a')
except:
pass
rotatee = newbuttonname
thispersonwasrotated(rotatee)
writethisdown.close()
…. and meanwhile within the makebutton function:
for someuser in listofusers:
username = someuser
newbuttonname = username
newbuttonname = Tkinter.Button(win, text = newbuttonname, command = lambda:click_one(username))
newbuttonname.pack()
You are almost there. You simply need to pass the name via lambda or functools.partial:
You can use this same technique to pass in the actual wodget, or any other data.