[Full] Membuat Aplikasi Absensi Siswa/Mahasiswa Menggunakan Python (Tkinter, openpyxl)

3 min read 2 hours ago
Published on Nov 24, 2024 This response is partially generated with the help of AI. It may contain inaccuracies.

Table of Contents

Introduction

This tutorial will guide you through creating a student attendance application using Python with the Tkinter library for the graphical user interface and openpyxl for Excel file handling. The application is useful for educators looking to manage attendance records efficiently.

Step 1: Setting Up Your Environment

Before you start coding, ensure you have the necessary tools installed.

  1. Install Python: Download and install Python from the official website.
  2. Install Required Libraries:
    • Open a command prompt or terminal.
    • Run the following commands to install Tkinter and openpyxl:
      pip install tk
      pip install openpyxl
      

Step 2: Creating the Basic Application Structure

Now you will create the basic structure of your Tkinter application.

  1. Import Libraries: Start your Python script by importing the required libraries:

    import tkinter as tk
    from openpyxl import Workbook
    
  2. Set Up the Main Window: Create the main application window:

    root = tk.Tk()
    root.title("Aplikasi Absensi Siswa/Mahasiswa")
    

Step 3: Designing the User Interface

Design the user interface to allow user input for attendance.

  1. Create Input Fields:

    • Add labels and entry fields for student name and attendance status.
    tk.Label(root, text="Nama Siswa:").grid(row=0, column=0)
    student_name = tk.Entry(root)
    student_name.grid(row=0, column=1)
    
    tk.Label(root, text="Status Kehadiran:").grid(row=1, column=0)
    attendance_status = tk.Entry(root)
    attendance_status.grid(row=1, column=1)
    
  2. Add Buttons:

    • Create buttons for submitting attendance and saving records.
    def submit_attendance():
        # Function to handle attendance submission
        pass
    
    submit_button = tk.Button(root, text="Kirim", command=submit_attendance)
    submit_button.grid(row=2, column=0, columnspan=2)
    

Step 4: Implementing Attendance Logic

Add the functionality to handle attendance submissions.

  1. Create a Function to Save Attendance: Implement the logic to save attendance data to an Excel file:

    def submit_attendance():
        wb = Workbook()
        ws = wb.active
        ws.append([student_name.get(), attendance_status.get()])
        wb.save("attendance.xlsx")
        student_name.delete(0, tk.END)
        attendance_status.delete(0, tk.END)
    
  2. Handle Data Validation: Ensure that the user inputs valid data before saving it:

    def submit_attendance():
        if student_name.get() and attendance_status.get():
            wb = Workbook()
            ws = wb.active
            ws.append([student_name.get(), attendance_status.get()])
            wb.save("attendance.xlsx")
            student_name.delete(0, tk.END)
            attendance_status.delete(0, tk.END)
        else:
            tk.messagebox.showwarning("Input Error", "Please fill in all fields.")
    

Step 5: Running the Application

Finalize your script and run the application.

  1. Add the Main Loop: At the end of your script, include the following line to start the application:

    root.mainloop()
    
  2. Test the Application:

    • Run your script and test the attendance application by entering student names and statuses.

Conclusion

You have successfully created a basic student attendance application using Python and Tkinter. This application allows teachers to input and save attendance records to an Excel file. To enhance your application, consider adding features like viewing past records or generating attendance reports. Explore the source code available at GitHub for further improvements and functionalities.