I am a teacher. Using Tkinter and Openpyxl I need to code a graphical user interface so I could click on a student's name “linked” with a checkbutton square and display his/her marks (saved on a “.xlsx” file) whenever his/her checkbutton is active. How can I create a set of widgets/checkbuttons that I can refer individually later on? My code fails.
![[Image: 9lWrw.png]](https://i.stack.imgur.com/9lWrw.png)
![[Image: iDH9e.png]](https://i.stack.imgur.com/iDH9e.png)
![[Image: 9lWrw.png]](https://i.stack.imgur.com/9lWrw.png)
![[Image: iDH9e.png]](https://i.stack.imgur.com/iDH9e.png)
# -*- coding: utf-8 -*-
from tkinter import *
import openpyxl
wb = openpyxl.load_workbook('marks.xlsx', data_only=True)
sheet = wb.active
names_and_rows = {}
for i in range(2, sheet.max_row + 1):
name = sheet.cell(row=i, column=1).value
names_and_rows[name] = i
root = Tk()
root.title("Student's marks")
students_names = Frame(root, bd=1, relief="solid")
students_names.pack(side="left")
student_marks = Frame(root, bd=1, relief="solid")
student_marks.pack(side="right")
message = Label(student_marks, text="You still haven't checked on a
ny student's name")
message.pack()
def get_marks(v):
marks = ""
for i in range(2, sheet.max_column + 1):
information = str(sheet.cell(row=1, column=i).value) + ": "
+ str(sheet.cell(row=v, column=i).value) + "\n"
marks = marks + information
if (v.get() == 1):
message.config(text=marks)
else:
message.config(text="You still haven't checked on any
student's name")
list_of_widgets = []
for k, v in names_and_rows.items():
square = Checkbutton(students_names, variable=v, onvalue=1,
offvalue=0, text=k, command=lambda: get_marks(v))
list_of_widgets.append(square)
square.pack()
root.mainloop()
