Introduction:
Managing student attendance is one of the crucial aspects of any classroom or educational setting. Keeping track of who’s present and who’s not can become challenging, especially when done manually. This inspired me to develop a Python-based student attendance checker using Tkinter. In this blog, I’ll share the full source code, explain how it works, and even discuss potential features you can add to enhance its functionality.
This project is a simple yet powerful tool that can be useful for teachers, educational institutions, or even parents who homeschool their children. If you’re looking to learn Python, Tkinter, or just automate tedious tasks, this project is perfect for you!
Project Description:
The attendance checker app takes a list of students’ names and compares it against a pre-defined list for each class section (like Section A or Section B). The app then identifies any students missing from the input list. The user interface is designed using Tkinter, making it intuitive and user-friendly.
Key Features:
- Dropdown menu to select different sections.
- Input box to paste student names.
- Output box displays missing student names with checkboxes for marking them.
- Clear button to reset inputs and outputs.
- Total absent student count displayed dynamically.
This app can be used as-is or further extended to add more functionality.
Full Code:
Below is the complete code for the student attendance checker app. I’ve included detailed comments for each section to help you understand how it works.
import tkinter as tk
from tkinter import ttk, messagebox
from PIL import Image, ImageTk
def convert_vertical_to_horizontal(input_string):
return ', '.join(line.strip() for line in input_string.split('\n') if line.strip())
def replace_backslashes(input_list, replacement_char):
return [item.replace('\\', replacement_char).upper() for item in input_list]
def check_missing_from_input(input_data, dictionary):
dictionary = [item.upper() for item in dictionary]
input_data = [item.upper() for item in input_data]
return [item for item in dictionary if item not in input_data and item.replace('>', '\\') not in input_data]
def on_check_missing():
user_input = input_box.get("1.0", tk.END).strip()
formatted_input = convert_vertical_to_horizontal(user_input)
user_input_list = [item.strip() for item in formatted_input.split(',')]
selected_section = section_var.get()
if selected_section == "Section A":
student_dictionary = section_a_students
elif selected_section == "Section B":
student_dictionary = section_b_students
else:
messagebox.showerror("Error", "Please select a valid Section.")
return
missing_from_input = check_missing_from_input(user_input_list, student_dictionary)
# Clear previous content in output box
output_box.delete("1.0", tk.END)
if not missing_from_input:
output_box.insert(tk.END, "All students are present in your input.\n", "success")
missing_count_label.config(text="Total absent students: 0")
else:
for student in missing_from_input:
var = tk.IntVar()
checkbox = tk.Checkbutton(
output_box,
text=student,
variable=var,
bg="white", # Background for the checkboxes
fg="black", # Text color
anchor="w",
selectimage=check_image, # Use black check mark image
image=empty_image, # Show empty image when unchecked
compound="left"
)
output_box.window_create(tk.END, window=checkbox)
output_box.insert(tk.END, "\n")
# Display total count of missing students
missing_count_label.config(text=f"Total absent students: {len(missing_from_input)}")
output_box.yview_moveto(0)
def clear_text_boxes():
input_box.delete("1.0", tk.END)
output_box.delete("1.0", tk.END)
missing_count_label.config(text="Total absent students: 0")
root = tk.Tk()
root.title("Find absent Students")
root.geometry("500x650")
root.configure(bg="#2b2b2b")
section_a_students = [
r"John",
r"Virat",
r"Emily",
r"Raj",
r"Alice",
r"Zara",
r"Leo",
r"Priya",
r"Mohammed",
r"Olivia",
r"Samuel",
r"Ayesha",
r"David",
r"Sophia",
r"Anil",
r"Isabella",
r"Karan",
r"Ella",
r"Aarav",
r"Nina"
]
section_b_students = [
r"Liam",
r"Anika",
r"Noah",
r"Ravi",
r"Ava",
r"Sanjay",
r"Mia",
r"Riya",
r"Ethan",
r"Tara",
r"Daniel",
r"Isha",
r"Lucas",
r"Neha",
r"James",
r"Kavya",
r"Benjamin",
r"Manav",
r"Grace",
r"Aleena"
]
black_check_image = Image.new('RGB', (15, 15), "black")
empty_image = Image.new('RGBA', (15, 15), (255, 255, 255, 0))
check_image = ImageTk.PhotoImage(black_check_image)
empty_image = ImageTk.PhotoImage(empty_image)
bg_color = "#2b2b2b"
text_color = "#f0f0f0"
button_color = "#4c4c4c"
highlight_color = "#1c1c1c"
hover_color = "#3b3b3b"
heading = tk.Label(root, text="Check absent student", bg=bg_color, fg="cyan", font=("Arial", 14, "bold"),
relief="ridge", padx=5, pady=5)
heading.pack(pady=(10, 20))
section_var = tk.StringVar(value="Section B")
style = ttk.Style()
style.theme_use("clam")
style.configure("TMenubutton", background=button_color, foreground=text_color)
style.map("TMenubutton", background=[("active", hover_color)])
section_label = tk.Label(root, text="Select Section:", bg=bg_color, fg=text_color)
section_label.pack(pady=5)
section_dropdown = ttk.OptionMenu(root, section_var, "Section A", "Section B", "Section A")
section_dropdown.pack(pady=5)
instructions = tk.Label(root, text="Enter each student name on a new line:", bg=bg_color, fg="cyan")
instructions.pack(pady=10)
input_frame = tk.Frame(root, bg=bg_color)
input_box = tk.Text(input_frame, height=5, width=40, bg=highlight_color, fg=text_color, insertbackground="white",
relief="sunken", bd=3)
input_scrollbar = tk.Scrollbar(input_frame, command=input_box.yview)
input_box.configure(yscrollcommand=input_scrollbar.set)
input_box.pack(side=tk.LEFT, fill=tk.BOTH, expand=True)
input_scrollbar.pack(side=tk.RIGHT, fill=tk.Y)
input_frame.pack(pady=5)
check_button = tk.Button(root, text="Check absent Student", command=on_check_missing, bg=button_color, fg="yellow",
activebackground=highlight_color, relief="raised", bd=3)
check_button.pack(pady=10)
output_frame = tk.Frame(root, bg=bg_color)
output_box = tk.Text(output_frame, height=10, width=40, bg="white", fg="black", insertbackground="black",
relief="sunken", bd=3)
output_scrollbar = tk.Scrollbar(output_frame, command=output_box.yview)
output_box.configure(yscrollcommand=output_scrollbar.set)
output_box.tag_configure("success", foreground="green")
output_box.pack(side=tk.LEFT, fill=tk.BOTH, expand=True)
output_scrollbar.pack(side=tk.RIGHT, fill=tk.Y)
output_frame.pack(pady=5)
# Label to show the total count of missing students
missing_count_label = tk.Label(root, text="Total absent students: 0", bg=bg_color, fg="white",
font=("Arial", 10, "bold"))
missing_count_label.pack(pady=5)
clear_button = tk.Button(root, text="Clear", command=clear_text_boxes, bg=button_color, fg="red",
activebackground=highlight_color, relief="raised", bd=3)
clear_button.pack(pady=10)
root.mainloop()
How to Use:
- Download and install Python on your system if you haven’t already.
- Install the required Python modules (
tkinter
,PIL
). bash code :pip install pillow
- Copy the code above into a
.py
file. - Run the Python script.
- Select the appropriate section from the dropdown, enter the list of student names, and click “Check absent Student” to identify missing students.
“Building this project has been a game-changer for me as a System Analyst who is constantly looking for ways to automate repetitive tasks. The student attendance checker not only helped me streamline attendance tracking for my daughter’s homeschooling sessions but also gave me hands-on experience with Python and Tkinter. I highly recommend this project for anyone interested in learning automation and Python GUIs.
Vinod Gill
Coder
Discover more from Quickinfoz
Subscribe to get the latest posts sent to your email.