0% found this document useful (0 votes)
6 views

Python Code[2]

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Python Code[2]

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

import tkinter as tk

from tkinter import messagebox


import os

# File path to store data


file_path = r"C:\Users\veeresh_h9\Videos\mini project\account_data.txt"

# Function to save form data


def save_data():
full_name = full_name_entry.get()
dob = dob_entry.get()
email = email_entry.get()
phone = phone_entry.get()
address = address_entry.get("1.0", tk.END).strip()
account_type = account_type_var.get()
branch_location = branch_location_var.get()

# Validate fields
if not (full_name and dob and email and phone and address and account_type and
branch_location):
messagebox.showerror("Error", "All fields are required!")
return

# Prepare data to save


data = (
f"Full Name: {full_name}\n"
f"Date of Birth: {dob}\n"
f"Email: {email}\n"
f"Phone: {phone}\n"
f"Address: {address}\n"
f"Account Type: {account_type}\n"
f"Branch Location: {branch_location}\n"
f"-----------------------------\n"
)

# Ensure directory exists


os.makedirs(os.path.dirname(file_path), exist_ok=True)

# Save data to file


with open(file_path, "a") as file:
file.write(data)

# Clear form
full_name_entry.delete(0, tk.END)
dob_entry.delete(0, tk.END)
email_entry.delete(0, tk.END)
phone_entry.delete(0, tk.END)
address_entry.delete("1.0", tk.END)
account_type_var.set("")
branch_location_var.set("")
messagebox.showinfo("Success", "Account details saved successfully!")

# Create GUI window


root = tk.Tk()
root.title("Bank Account Opening Form")

# Full Name
tk.Label(root, text="Full Name").grid(row=0, column=0, padx=10, pady=5, sticky="w")
full_name_entry = tk.Entry(root, width=30)
full_name_entry.grid(row=0, column=1, padx=10, pady=5)

# Date of Birth
tk.Label(root, text="Date of Birth").grid(row=1, column=0, padx=10, pady=5, sticky="w")
dob_entry = tk.Entry(root, width=30)
dob_entry.grid(row=1, column=1, padx=10, pady=5)

# Email
tk.Label(root, text="Email Address").grid(row=2, column=0, padx=10, pady=5, sticky="w")
email_entry = tk.Entry(root, width=30)
email_entry.grid(row=2, column=1, padx=10, pady=5)

# Phone Number
tk.Label(root, text="Phone Number").grid(row=3, column=0, padx=10, pady=5, sticky="w")
phone_entry = tk.Entry(root, width=30)
phone_entry.grid(row=3, column=1, padx=10, pady=5)

# Address
tk.Label(root, text="Residential Address").grid(row=4, column=0, padx=10, pady=5, sticky="w")
address_entry = tk.Text(root, width=30, height=4)
address_entry.grid(row=4, column=1, padx=10, pady=5)

# Account Type
tk.Label(root, text="Account Type").grid(row=5, column=0, padx=10, pady=5, sticky="w")
account_type_var = tk.StringVar()
account_type_menu = tk.OptionMenu(root, account_type_var, "Savings Account", "Current
Account", "Fixed Deposit")
account_type_menu.grid(row=5, column=1, padx=10, pady=5, sticky="w")

# Branch Location
tk.Label(root, text="Preferred Branch Location").grid(row=6, column=0, padx=10, pady=5,
sticky="w")
branch_location_var = tk.StringVar()
branch_location_menu = tk.OptionMenu(root, branch_location_var, "New York", "Los Angeles",
"Chicago", "Houston", "Miami")
branch_location_menu.grid(row=6, column=1, padx=10, pady=5, sticky="w")

# Submit Button
submit_button = tk.Button(root, text="Submit", command=save_data)
submit_button.grid(row=7, column=0, columnspan=2, pady=20)

# Run the GUI event loop


root.mainloop()

You might also like