I want to create a simple interface that takes a list of student names that are in your classroom as input and outputs a row of buttons for each one,
ex:
John Johnson (Idle)(Talking)(etc)
Doris Day (Idle)(Talking)(etc)
When each button is clicked, it writes a log of that student name and behavior to an output file.
My problem is that it currently makes every button write a log for whatever student is last on the list of student names. It is my understanding that this is due to 'late binding', but this time I can't resolve it on my own in the time I have before school starts.
currentperiod= [studentname1, studentname2, ...etc]
def behaviorlog(name, behavior):
write name and behavior to a spreadsheet
def idle():
name=currentperiod[x]
behavior='Idle'
behaviorlog(name,behavior)
def talking():
name=currentperiod[x]
behavior='Talking'
behaviorlog(name,behavior)
def late():
name=currentperiod[x]
behavior='Late'
behaviorlog(name,behavior)
def rude():
name=currentperiod[x]
behavior='Rude'
behaviorlog(name,behavior)
def misplaced():
name=currentperiod[x]
behavior='Misplaced'
behaviorlog(name,behavior)
from tkinter import *
master= Tk()
for x in range(len(currentperiod)):
Label(master, text=currentperiod[x]).grid(row=x, sticky = W)
button1=Button(master, text='Idle', command=idlemaker)
button1.grid(row=x, column=1, sticky=W, pady=4)
button2=Button(master, text='Talking', command=talking)
button2.grid(row=x, column=2, sticky=W, pady=4)
button3=Button(master, text='Late', command=late)
button3.grid(row=x, column=3, sticky=W, pady=4)
button4=Button(master, text='Rude', command=rude)
button4.grid(row=x, column=4, sticky=W, pady=4)
button5=Button(master, text='Misplaced', command=misplaced)
button5.grid(row=x, column=5, sticky=W, pady=4)
mainloop( )