Python Simple Registration Form — Straightforward Data Capture

Rahul Patodi
Wiki Flood
Published in
8 min readFeb 17, 2024

The “Flood-Registration Form” project is a simple yet effective Tkinter-based application designed to facilitate user registration with essential information such as first name, last name, email, contact number, password, and gender.

The user-friendly graphical interface provides input fields for each piece of information, along with dropdown options for selecting the gender. The form is visually appealing, featuring a light green background with purple text for labels and blue text for user input.

Upon submitting the registration form by clicking the “Submit” button, the application gathers the entered details and displays a confirmation message in blue, indicating the successful creation of the registration.

This Python Simple Registration form project serves as a basic template that can be extended and customized for various applications requiring user registration functionalities, such as event registrations, membership sign-ups, or any scenario where user data needs to be collected.

The use of Tkinter, a standard GUI library for Python, makes it accessible for developers to enhance and tailor the application to meet specific requirements.

Simple registration form using Tkinter
Simple registration form using Tkinter

About Python Simple Registration Form

The “Flood-Registration Form” project is a simple and intuitive Tkinter-based application designed to streamline the user registration process. With a clean and visually appealing interface, the registration form captures essential details including first name, last name, email, contact number, password, and gender.

The form elements are thoughtfully arranged in a grid layout, featuring purple-colored labels for a visually distinct look. Upon submission, the entered information is displayed in a confirmation message with a blue text color, signaling the successful creation of the registration.

This Python Simple Registration Form project serves as a versatile template that can be further customized for various registration scenarios, offering a user-friendly solution for collecting and processing user data. The integration of Tkinter ensures cross-platform compatibility, making it accessible to a wide range of users.

Prerequisites for Python Simple Registration Form

Python Installation:

Ensure that Python is installed on your system. Tkinter, the graphical user interface library used in this project, is typically included with standard Python installations.

Python Tkinter Module:

Tkinter is used for creating the graphical user interface in this project. Although Tkinter is included with standard Python installations, it’s essential to confirm its presence. You can check Tkinter’s availability by attempting to import it in a Python script or shell. If not installed, you can install it using the following command:

“pip install tk”

Python Simple Registration Form Project Structure

The structure of the “Flood-Registration Form” project can be outlined in several key points:

1. Main Window Setup:

The project begins by creating the main window using the `tk.Tk()` constructor. The window’s title is set to “Flood-Registration Form,” and its initial dimensions are configured to be 400x400 pixels. The background color is set to light green using the `configure` method.

2. User Interface Components:

Labels, Entry widgets, a Combobox, and a Button are created to construct the user interface. Each user input field, such as first name, last name, email, contact number, and password, is associated with a corresponding `ttk.Entry` widget. The gender is captured using a `ttk.Combobox`. The labels and widgets are organized in a grid layout using the `grid` method.

3. Submit Form Functionality:

A function named `submit_form` is defined to handle the submission of the registration form. This function retrieves the values entered by the user, such as first name, last name, email, contact number, password, and gender. It then updates a `ttk.Label` named `result_label` to display a confirmation message with the entered information in blue color, indicating a successful form submission.

4. Styling and Appearance:

The labels for user input fields are configured to have purple text color. The “Submit” button is styled with a red foreground color using `ttk.Style`. The `ttk.Combobox` for gender is set to a read-only state, and its default value is set to “Male.”

5. Tkinter Main Loop:

The project concludes with the initiation of the Tkinter main loop using the `root.mainloop()` method. This loop continuously runs, allowing the graphical user interface to be interactive and respond to user input. It ensures that the application remains open until the user decides to close the window.

Implementation of Python Simple Registration Form

Step 1: Import Necessary Libraries

Import the necessary libraries, including `tkinter` for GUI development.

import tkinter as tk
from tkinter import ttk

Step 2: Define the `submit_form` Function

Define a function `submit_form` to be called when the user clicks the “Submit” button. This function retrieves the user input values, formats a success message, and updates the result label.

def submit_form():
# Retrieve values from the form
first_name = entry_first_name.get()
last_name = entry_last_name.get()
email = entry_email.get()
contact_number = entry_contact_number.get()
password = entry_password.get()
gender = gender_var.get()


# Display the submitted information in blue color
result_label.config(text=f"Registration Form Successfully Created!\n"
f"First Name: {first_name}\n"
f"Last Name: {last_name}\n"
f"Email: {email}\n"
f"Contact Number: {contact_number}\n"
f"Password: {password}\n"
f"Gender: {gender}", foreground="blue")

Data Retrieval:

The `submit_form` function retrieves the user-entered data from the Tkinter entry widgets (`entry_first_name`, `entry_last_name`, `entry_email`, `entry_contact_number`, `entry_password`) and the combobox (`gender_var`). These values represent the user’s first name, last name, email, contact number, password, and selected gender, respectively.

Display Confirmation Message:

After retrieving the user input, the function updates the text of the `result_label` widget to display a confirmation message. The message includes a success statement along with the user-entered information formatted appropriately. The `foreground` attribute of the `result_label` is set to “blue” to ensure the message is displayed in blue color, indicating a successful form submission.

Step 3: Create the Main Window

Create the main window and configure its properties.

root = tk.Tk()
root.title("Flood-Registration Form")
root.geometry("400x400")
root.configure(bg="lightgreen")

Tk()- class is created, representing the main window

title()- sets the window title

geometry()- sets the window size (width x height)

configure()- is used to set the background color

Step 4: Create User Interface Components

Create labels, entry widgets, combobox, and buttons for the registration form

# Create labels
label_first_name = ttk.Label(root, text="First Name:", foreground="purple")
label_last_name = ttk.Label(root, text="Last Name:", foreground="purple")
label_email = ttk.Label(root, text="Email:", foreground="purple")
label_contact_number = ttk.Label(root, text="Contact Number:", foreground="purple")
label_password = ttk.Label(root, text="Password:", foreground="purple")
label_gender = ttk.Label(root, text="Gender:", foreground="purple")


# Create entry widgets
entry_first_name = ttk.Entry(root)
entry_last_name = ttk.Entry(root)
entry_email = ttk.Entry(root)
entry_contact_number = ttk.Entry(root)
entry_password = ttk.Entry(root, show="*")
# Create a Combobox for gender
gender_var = tk.StringVar()
gender_combobox = ttk.Combobox(root, textvariable=gender_var, values=["Male", "Female"], state="readonly")
gender_combobox.set("Male") # Default value
# Create submit button
submit_button = ttk.Button(root, text="Submit", command=submit_form, style="TButton")
# Create label for displaying the result
result_label = ttk.Label(root, text="", foreground="blue")

User Interface Elements:

This code segment initializes various Tkinter widgets for the registration form’s graphical user interface. It includes labels (`label_first_name`, `label_last_name`, etc.) for each input field, entry widgets (`entry_first_name`, `entry_last_name`, etc.) to capture user input, a dropdown (`gender_combobox`) for selecting gender, a submit button (`submit_button`), and a label (`result_label`) to display the submission result.

Styling and Configuration:

The labels for user input fields are created using `ttk.Label`, configured with the text and a purple foreground color. Entry widgets capture user input, and the password entry uses the `show=”*”` attribute to hide entered characters. The gender_combobox is a dropdown with options “Male” and “Female,” initially set to “Male.” The submit button is configured with the command `submit_form` and styled with a red foreground color. The `result_label` is configured to display the submission result in blue text.

Step 5: Place Widgets on the Grid

Arrange the labels, entry widgets, and buttons on the grid layout.

# Place widgets on the grid
label_first_name.grid(row=0, column=0, padx=10, pady=5, sticky="w")
label_last_name.grid(row=1, column=0, padx=10, pady=5, sticky="w")
label_email.grid(row=2, column=0, padx=10, pady=5, sticky="w")
label_contact_number.grid(row=3, column=0, padx=10, pady=5, sticky="w")
label_password.grid(row=4, column=0, padx=10, pady=5, sticky="w")
label_gender.grid(row=5, column=0, padx=10, pady=5, sticky="w")


entry_first_name.grid(row=0, column=1, padx=10, pady=5, sticky="w")
entry_last_name.grid(row=1, column=1, padx=10, pady=5, sticky="w")
entry_email.grid(row=2, column=1, padx=10, pady=5, sticky="w")
entry_contact_number.grid(row=3, column=1, padx=10, pady=5, sticky="w")
entry_password.grid(row=4, column=1, padx=10, pady=5, sticky="w")
gender_combobox.grid(row=5, column=1, padx=10, pady=5, sticky="w")


submit_button.grid(row=6, column=0, columnspan=2, pady=10)
result_label.grid(row=7, column=0, columnspan=2, pady=10)

Label Placement:

Labels for first name, last name, email, contact number, password, and gender are positioned in the left column (column 0) of the grid. The `padx` and `pady` parameters specify the padding around each label, and the `sticky` parameter ensures that the labels are left-aligned.

Entry, Combobox, and Button Placement:

Entry widgets for user input, the gender Combobox, and the Submit button are placed in the right column (column 1) of the grid. Similar to labels, the `padx` and `pady` parameters control the padding around each widget. The `columnspan` parameter for the Submit button ensures it spans across both columns. The `result_label` is placed below the Submit button with a `row` value of 7 and a `columnspan` of 2.

Step 6: Configure Style

Configure the style for the “Submit” button.

# Configure style for the submit button
style = ttk.Style()
style.configure("TButton", foreground="red")

Style Initialization:

`style = ttk.Style()` initializes an instance of the `ttk.Style` class, allowing customization of the appearance of Tkinter widgets.

Button Styling:

`style.configure(“TButton”, foreground=”red”)` configures the style for the Tkinter Button widget with the name “TButton.” In this case, it sets the foreground color (text color) of the button to red. This line of code defines the visual aspect of the “Submit” button in the registration form, giving it a distinctive red color.

Step 7: Run the Tkinter Main Loop

Start the Tkinter main loop to display the window and handle user interactions.

# Run the Tkinter main loop
root.mainloop()

Python Code

import tkinter as tk
from tkinter import ttk


def submit_form():
# Retrieve values from the form
first_name = entry_first_name.get()
last_name = entry_last_name.get()
email = entry_email.get()
contact_number = entry_contact_number.get()
password = entry_password.get()
gender = gender_var.get()


# Display the submitted information in blue color
result_label.config(text=f"Registration Form Successfully Created!\n"
f"First Name: {first_name}\n"
f"Last Name: {last_name}\n"
f"Email: {email}\n"
f"Contact Number: {contact_number}\n"
f"Password: {password}\n"
f"Gender: {gender}", foreground="blue")


# Create main window
root = tk.Tk()
root.title("Flood-Registration Form")
root.geometry("400x400")
root.configure(bg="lightgreen")


# Create labels
label_first_name = ttk.Label(root, text="First Name:", foreground="purple")
label_last_name = ttk.Label(root, text="Last Name:", foreground="purple")
label_email = ttk.Label(root, text="Email:", foreground="purple")
label_contact_number = ttk.Label(root, text="Contact Number:", foreground="purple")
label_password = ttk.Label(root, text="Password:", foreground="purple")
label_gender = ttk.Label(root, text="Gender:", foreground="purple")


# Create entry widgets
entry_first_name = ttk.Entry(root)
entry_last_name = ttk.Entry(root)
entry_email = ttk.Entry(root)
entry_contact_number = ttk.Entry(root)
entry_password = ttk.Entry(root, show="*")


# Create a Combobox for gender
gender_var = tk.StringVar()
gender_combobox = ttk.Combobox(root, textvariable=gender_var, values=["Male", "Female"], state="readonly")
gender_combobox.set("Male") # Default value


# Create submit button
submit_button = ttk.Button(root, text="Submit", command=submit_form, style="TButton")


# Create label for displaying the result
result_label = ttk.Label(root, text="", foreground="blue")


# Place widgets on the grid
label_first_name.grid(row=0, column=0, padx=10, pady=5, sticky="w")
label_last_name.grid(row=1, column=0, padx=10, pady=5, sticky="w")
label_email.grid(row=2, column=0, padx=10, pady=5, sticky="w")
label_contact_number.grid(row=3, column=0, padx=10, pady=5, sticky="w")
label_password.grid(row=4, column=0, padx=10, pady=5, sticky="w")
label_gender.grid(row=5, column=0, padx=10, pady=5, sticky="w")


entry_first_name.grid(row=0, column=1, padx=10, pady=5, sticky="w")
entry_last_name.grid(row=1, column=1, padx=10, pady=5, sticky="w")
entry_email.grid(row=2, column=1, padx=10, pady=5, sticky="w")
entry_contact_number.grid(row=3, column=1, padx=10, pady=5, sticky="w")
entry_password.grid(row=4, column=1, padx=10, pady=5, sticky="w")
gender_combobox.grid(row=5, column=1, padx=10, pady=5, sticky="w")


submit_button.grid(row=6, column=0, columnspan=2, pady=10)
result_label.grid(row=7, column=0, columnspan=2, pady=10)


# Configure style for the submit button
style = ttk.Style()
style.configure("TButton", foreground="red")


# Run the Tkinter main loop
root.mainloop()

Python Simple Registration Form Output

Simple registration form using Tkinter output
Tkinter Simple registration form

Conclusion

The “Flood-Registration Form” project represents a concise and effective application leveraging Tkinter for user registration. With its intuitive design, the Python Registration Form project ensures a seamless user experience, presenting a visually pleasing registration form with carefully chosen color schemes.

The integration of Tkinter’s GUI components facilitates ease of use, making it accessible to a broad audience. The success message in blue, displayed upon form submission, adds a touch of interactivity, enhancing the overall user interaction.

Beyond its simplicity, the Python Simple Registration Form project serves as a robust foundation for developers, showcasing the potential for further customization and expansion. Its adaptability makes it a valuable starting point for those exploring Tkinter-based applications, demonstrating the balance between functionality and user-friendly design.

--

--