How to Create a Python Excel Data Entry Form with CustomTkinter
- By Pratyush Mishra
In today’s digital world, automating data entry processes can save time and reduce errors. Python, combined with CustomTkinter for GUI development and openpyxl for Excel manipulation, provides an excellent solution for creating a professional and modern data entry form. In this article, we’ll walk through how to build a sleek Excel-based data entry application using Python.
Project Overview
In this project, we will: ✅ Build a GUI application using CustomTkinter ✅ Collect user input through text fields and buttons ✅ Save entered data automatically into an Excel spreadsheet ✅ Implement form validation for accurate data entry ✅ Use Buildfy to design a modern UI
This project is perfect for beginners and intermediate developers looking to automate data collection.
Tools and Libraries Required
Before starting, ensure you have the following installed:
pip install customtkinter openpyxl
CustomTkinter – For building a modern, dark-themed GUI
openpyxl – For handling Excel file operations
Step 1: Setting Up the GUI with CustomTkinter
We begin by creating the main application window using CustomTkinter.
import customtkinter as ctk
from tkinter import messagebox
import openpyxl
import os
class DataEntryApp(ctk.CTk):
def __init__(self):
super().__init__()
self.title('Excel Data Entry Form')
self.geometry('800x600')
self.configure_ui()
def configure_ui(self):
ctk.set_appearance_mode("dark")
ctk.set_widget_scaling(1.0)
self.create_widgets()
def create_widgets(self):
self.create_label("Name", 50, 50)
self.name_entry = self.create_entry(200, 50, "Enter Name")
self.create_label("Contact No.", 50, 100)
self.contact_entry = self.create_entry(200, 100, "Enter Contact No.")
self.create_label("Age", 50, 150)
self.age_entry = self.create_entry(200, 150, "Enter Age")
self.submit_button = ctk.CTkButton(self, text="Submit", command=self.submit_data, width=340)
self.submit_button.place(x=200, y=250)
def create_label(self, text, x, y):
label = ctk.CTkLabel(self, text=text, text_color='#FFFFFF', font=('Arial', 14))
label.place(x=x, y=y)
def create_entry(self, x, y, placeholder):
entry = ctk.CTkEntry(self, width=300, placeholder_text=placeholder)
entry.place(x=x, y=y)
return entry
Step 2: Saving Data to an Excel File
Now, let’s implement the functionality to store the form data into an Excel spreadsheet using openpyxl.
def submit_data(self):
name = self.name_entry.get()
contact = self.contact_entry.get()
age = self.age_entry.get()
if not name or not contact or not age:
messagebox.showwarning("Warning", "All fields must be filled!")
return
file_path = "data.xlsx"
if not os.path.exists(file_path):
workbook = openpyxl.Workbook()
sheet = workbook.active
sheet.append(["Name", "Contact No.", "Age"])
workbook.save(file_path)
workbook = openpyxl.load_workbook(file_path)
sheet = workbook.active
sheet.append([name, contact, age])
workbook.save(file_path)
messagebox.showinfo("Success", "Data saved successfully!")
self.clear_fields()
Step 3: Clearing Input Fields
We also need a function to clear all fields after submission.
def clear_fields(self):
self.name_entry.delete(0, 'end')
self.contact_entry.delete(0, 'end')
self.age_entry.delete(0, 'end')
Final Step: Running the Application
Finally, let’s run the application:
if __name__ == '__main__':
app = DataEntryApp()
app.mainloop()
Conclusion
By following this tutorial, you have successfully built a Python-based GUI application that captures user data and stores it in an Excel spreadsheet. This project can be expanded further by adding:
🔹 More input fields for detailed data collection
🔹 A search and update feature for existing records
🔹 Integration with databases like SQLite or MySQL for advanced data storage
If you found this guide helpful, feel free to share and subscribe to our channel for more exciting Python projects! 🚀