lundi 30 août 2021

Python (tkinter) getting which checkbuttons are checked?

I'm trying to build a python app where we can make our working schedules. I want to be able to press 2 checkbuttons per employee and to export the ones that are checked into a CSV file. The way i have set up the code right now i'm generating the Checkbuttons in for loops, so i can't give them individual names/values. is there still a way i can see which ones are pressed?

(the variable "times" contains a list of all the available times, starting at 14:00 and ending at 23:00)

#building UI
master = Tk()
emplindex = 1
timeindex = 1
for i in times:
    timelabel = Label(master, text=" " + i + " ").grid(row=0, column=timeindex)
    timeindex +=1
for i in employees:
    namelabel = Label(master, text=i[1]).grid(row=emplindex, column=0)
    timeindex = 1
    for i in times:
        CB =  Checkbutton(master).grid(row=emplindex,column=timeindex)
        timeindex +=1
    emplindex +=1
buildbutton = ttk.Button(master, text = "BUILD SCHEDULE", command=lambda: buttonclicked()).grid(row=100)
def buttonclicked():
    selected = CB
master.mainloop()

This is what the ui outputs




Aucun commentaire:

Enregistrer un commentaire