import tkinter as tk
from tkinter import messagebox
import [Link]
# ---------------- Database Connection ---------------- #
conn = [Link](
host="localhost",
user="root", # your MySQL username
password="1234", # your MySQL password
database="rutva" # your database name
)
cur = [Link]()
# ---------------- Tkinter Root ---------------- #
root = [Link]()
[Link]("Travel Booking System")
[Link]("650x450")
[Link](bg="#fdf6e3")
current_user = None
current_user_id = None
# ---------------- Utility ---------------- #
def clear_frame():
for widget in root.winfo_children():
[Link]()
def get_next_id(table, column):
[Link](f"SELECT MAX({column}) FROM {table}")
max_id = [Link]()[0]
if max_id is None:
return 1
else:
return max_id + 1
# ---------------- Choice Page ---------------- #
def show_choice():
clear_frame()
[Link](root, text="Welcome to Travel Booking System",
font=("Arial", 18, "bold"), bg="#fdf6e3", fg="#4b3832").pack(pady=30)
[Link](root, text="Login", command=show_login,
width=20, height=2, bg="#e3caa5", fg="#3b2f2f",
font=("Arial", 12, "bold")).pack(pady=10)
[Link](root, text="Sign Up", command=show_signup,
width=20, height=2, bg="#e3caa5", fg="#3b2f2f",
font=("Arial", 12, "bold")).pack(pady=10)
[Link](root, text="Exit", command=[Link],
width=20, height=2, bg="#e3caa5", fg="#3b2f2f",
font=("Arial", 12, "bold")).pack(pady=20)
# ---------------- Home Page ---------------- #
def show_home():
clear_frame()
frame = [Link](root, bg="#fdf6e3", padx=20, pady=20)
[Link](expand=True, fill="both")
[Link](frame, text=f"Welcome, {current_user}",
font=("Helvetica", 20, "bold"), bg="#fdf6e3",
fg="#4b3832").pack(pady=20)
def styled_button(text, command):
return [Link](frame, text=text, width=25, height=2,
font=("Arial", 12, "bold"), bg="#e3caa5",
fg="#3b2f2f", activebackground="#d2b48c",
activeforeground="black", relief="flat",
command=command)
styled_button("Make a Booking", make_booking).pack(pady=10)
styled_button("Check My Bookings", check_bookings).pack(pady=10)
styled_button("Cancel a Booking", cancel_booking).pack(pady=10)
styled_button("Logout", show_choice).pack(pady=20)
# ---------------- Login ---------------- #
def login_user():
global current_user, current_user_id
username = entry_userid.get()
password = entry_password.get()
if not username or not password:
[Link]("Error", "Please enter Username and Password")
show_choice()
return
[Link]("SELECT UserID, Username FROM Users WHERE Username=%s AND Password=
%s",
(username, password))
result = [Link]()
if result:
current_user_id = result[0]
current_user = result[1]
show_home()
else:
[Link]("Error", "Invalid Login. Please Sign Up first.")
show_choice()
def show_login():
clear_frame()
global entry_userid, entry_password
[Link](root, text="Login", font=("Arial", 20, "bold"),
bg="#fdf6e3").pack(pady=20)
[Link](root, text="Username:", font=("Arial", 12), bg="#fdf6e3").pack()
entry_userid = [Link](root, font=("Arial", 12))
entry_userid.pack(pady=5)
[Link](root, text="Password:", font=("Arial", 12), bg="#fdf6e3").pack()
entry_password = [Link](root, show="*", font=("Arial", 12))
entry_password.pack(pady=5)
[Link](root, text="Login", command=login_user,
bg="#c9ada7", fg="black", font=("Arial", 12, "bold")).pack(pady=10)
# ---------------- Signup ---------------- #
def signup_user():
global current_user, current_user_id
username = entry_userid.get()
password = entry_password.get()
if not username or not password:
[Link]("Error", "Please enter Username and Password")
show_choice()
return
user_id = get_next_id("Users", "UserID")
try:
[Link]("INSERT INTO Users (UserID, Username, Password) VALUES (%s, %s,
%s)",
(user_id, username, password))
[Link]()
current_user_id = user_id
current_user = username
show_home()
except:
[Link]("Error", "Username already exists")
show_choice()
def show_signup():
clear_frame()
global entry_userid, entry_password
[Link](root, text="Sign Up", font=("Arial", 20, "bold"),
bg="#fdf6e3").pack(pady=20)
[Link](root, text="Choose Username:", font=("Arial", 12),
bg="#fdf6e3").pack()
entry_userid = [Link](root, font=("Arial", 12))
entry_userid.pack(pady=5)
[Link](root, text="Choose Password:", font=("Arial", 12),
bg="#fdf6e3").pack()
entry_password = [Link](root, show="*", font=("Arial", 12))
entry_password.pack(pady=5)
[Link](root, text="Sign Up", command=signup_user,
bg="#c9ada7", fg="black", font=("Arial", 12, "bold")).pack(pady=10)
# ---------------- Bookings ---------------- #
def make_booking():
global current_user_id
if current_user_id is None:
[Link]("Error", "Please login first!")
return
# Get any destination that exists
[Link]("SELECT DestinationID FROM Destinations LIMIT 1")
dest = [Link]()
if not dest:
[Link]("Error", "No destinations available! Please add one.")
return
dest_id = dest[0]
booking_id = get_next_id("Bookings", "BookingID")
[Link]("INSERT INTO Bookings (BookingID, UserID, DestinationID, StartDate,
EndDate) "
"VALUES (%s, %s, %s, %s, %s)",
(booking_id, current_user_id, dest_id, '2025-08-16', '2025-08-20'))
[Link]()
[Link]("Success", "Booking created successfully!")
def check_bookings():
[Link]("SELECT [Link], [Link], [Link], [Link] "
"FROM Bookings B "
"JOIN Destinations D ON [Link] = [Link] "
"JOIN Payments P ON [Link] = [Link] "
"WHERE [Link] = %s", (current_user_id,))
bookings = [Link]()
if not bookings:
[Link]("Bookings", "No bookings found.")
else:
details = "\n".join([f"Booking {b[0]}: {b[1]}, ₹{b[2]}, {b[3]}" for b in
bookings])
[Link]("My Bookings", details)
def cancel_booking():
[Link]("SELECT BookingID FROM Bookings WHERE UserID=%s",
(current_user_id,))
booking = [Link]()
if not booking:
[Link]("Error", "No bookings to cancel")
return
bid = booking[0]
[Link]("DELETE FROM Payments WHERE BookingID=%s", (bid,))
[Link]("DELETE FROM Bookings WHERE BookingID=%s", (bid,))
[Link]()
[Link]("Cancelled", f"Booking {bid} cancelled successfully.")
# ---------------- Start ---------------- #
show_choice()
[Link]()