You are on page 1of 24

Computer Science Project Report

Name: Fawaz Shaik


Class: 12
Year: 2023-2024
Contents

 Acknowledgement
 Introduction
 Hardware and Software requirements
 Why Python ?
 Source Code
 Out Put Series
 Further Development
Acknowledgment

I would like to extend my sincere appreciation and gratitude to the


following individuals and entities who played a crucial role in the
development of the Movie Ticket Booking System project:
Sir Mutha School
Principal , Samira mam:
Thank you to Principal Samira mam for fostering an environment that
encourages creativity and innovation. Your support has been instrumental
in the realization of this project.
Computer Science Teacher , Manoj sir:
A special acknowledgment to Manoj sir, our dedicated computer science
teacher, for their guidance, mentorship, and unwavering support
throughout the development process. Their expertise and encouragement
have been invaluable.
Friends
Heartfelt thanks to all my friends for their continuous encouragement,
feedback, and moral support. Your enthusiasm and shared excitement
made this project an enjoyable and collaborative journey.
Introduction

The Movie Ticket Booking System is a software application designed to


streamline and automate the process of booking movie tickets for
customers. This system provides an interactive graphical user interface
(GUI) built using Tkinter, a popular GUI toolkit for Python. The backend
of the application utilizes MySQL for database management.
Features:
User Authentication:
Users can log in with a registered username and password. New users
have the option to register, creating a new account for future logins.
Movie Selection:
After successful login, users can select a movie from the available
options. Date and time options for each movie are presented for selection.
Seat Booking:
Users can choose their seats for the selected movie, date, and time. A
graphical representation of available seats allows users to make informed
choices.
Payment Processing:
Once seats are selected, users proceed to the payment screen. The system
calculates the total amount based on the number of selected seats and a
predefined seat price.
Users can complete the payment process to confirm their booking.
Implementation:
Frontend: Tkinter
Tkinter is used to create an intuitive and user-friendly interface for users
to interact with the system.
Screens include login, movie selection, seat booking, and payment.

Backend: MySQL
MySQL is employed to store and manage user data, movie details, and
booking information.
SQL queries are executed to check login credentials, retrieve movie
details, and update seat bookings
How to Run:
Ensure Python, Tkinter, and MySQL Connector/Python are installed. Set
up the MySQL database and table as specified in the code.
Update the database connection parameters in the code.
Run the Python script.
This Movie Ticket Booking System provides a seamless and user-friendly
experience for customers to browse, select, and book movie tickets,
enhancing the efficiency of the ticket booking process. Users can enjoy
the convenience of reserving their preferred seats with just a few clicks.
Hardware And Software Requirements

Hardware Requirements:
Computer: Any standard desktop or laptop computer should be sufficient.

Operating System: The code should work on Windows, macOS, or Linux.


Ensure your operating system is supported by both Python and Tkinter.

MySQL Server: Since the code connects to a MySQL database, you need
access to a MySQL server. If you don't have one installed locally, you
might consider using a remote MySQL server.

Internet Connection: If you are using a remote MySQL server, you will
need an internet connection to connect to it.

Software Requirements:
Python: Ensure you have Python installed on your system. You can
download the latest version of Python from the official website.

Tkinter: Tkinter is included with most Python installations, so you


generally don't need to install it separately. However, for some systems,
you might need to install the Tkinter package explicitly. You can usually
install it using the package manager for your operating system.

MySQL Connector/Python: The code uses MySQL as a database


backend, so you'll need to have the MySQL Connector/Python
installed.You can install it using the following command:
pip install mysql-connector-python
Why Python ?

Python is a high-level, interpreted, interactive, and object-oriented


scripting language. Python was designed to be highly readable which uses
English keywords frequently whereas other languages use punctuation
and it has fewer syntactical constructions than other languages.

It is used in :

1. Software Development
2. Web Development
3. System Scripting
4. Mathematics

Python is Interpreted

It means that each line is processed one by one at runtime by the


interpreter and you do not need to compile your program before
executing it.

Python is Interactive

It means that you can actually sit at a Python prompt and interact with the
interpreter directly, to write and execute your programs.

Python supports the Object-Oriented style or technique of programming


that encapsulates code within objects

Python's success is that its source code is fairly easy-to-maintain. One


reason for that is, it is read and written like a lot of everyday English.
One of Python's greatest strengths is the bulk of the library, which makes
it very portable and cross-platform compatible. Python has libraries for
almost everything one can think of
Python can run on a wide variety of hardware platforms and has the same
interface on all platforms. You can run the same python program on
Windows, Linux, Mac, Raspberry Pi, Mango Pi, Android, etc
Python provides interfaces to all major commercial databases. It has
packages to communicate with SQL, NoSQL, etc. databases, ranging
from MongoDB to MySQL.
Source Code

import tkinter as tk
from tkinter import messagebox
import mysql.connector
from tkinter import ttk

# Function to check login credentials


def login():
username = entry_username.get()
password = entry_password.get()

try:
# Connect to the MySQL database
db = mysql.connector.connect(
host="localhost",
user="root",
password="",
database="MovieTicketDB"
)
cursor = db.cursor()

# Check if the provided username and password match the database


query = "SELECT * FROM users WHERE username=%s AND
password=%s"
cursor.execute(query, (username, password))
result = cursor.fetchone()
if result:
open_movie_selection_screen()
else:
messagebox.showerror("Login Failed", "Invalid username or
password")

db.close()
except mysql.connector.Error as err:
messagebox.showerror("Database Error", f"Error: {err}")
except Exception as e:
messagebox.showerror("Error", f"An error occurred: {e}")

# Function to open the movie selection screen


def open_movie_selection_screen():
movie_selection_window = tk.Toplevel(root)
movie_selection_window.title("Movie Selection")
movie_selection_window.geometry("800x600")

label_movie_selection = tk.Label(movie_selection_window,
text="Select a Movie", font=("Helvetica", 20))
label_movie_selection.pack(pady=20)

# Create a Combobox for movie selection


movie_combobox = ttk.Combobox(movie_selection_window,
values=["Movie 1", "Movie 2", "Movie 3"])
movie_combobox.pack()
movie_combobox.set("Movie 1")
label_date_selection = tk.Label(movie_selection_window, text="Select
Date", font=("Helvetica", 16))
label_date_selection.pack(pady=10)

# Create a Combobox for date selection


date_combobox = ttk.Combobox(movie_selection_window,
values=["2023-11-15", "2023-11-16", "2023-11-17"])
date_combobox.pack()
date_combobox.set("2023-11-15")

label_time_selection = tk.Label(movie_selection_window,
text="Select Time", font=("Helvetica", 16))
label_time_selection.pack(pady=10)

# Create a Combobox for time selection


time_combobox = ttk.Combobox(movie_selection_window,
values=["10:00 AM", "2:00 PM", "6:00 PM"])
time_combobox.pack()
time_combobox.set("10:00 AM")

def open_seat_booking_screen():
selected_movie = movie_combobox.get()
selected_date = date_combobox.get()
selected_time = time_combobox.get()

seat_booking_window = tk.Toplevel(movie_selection_window)
seat_booking_window.title("Seat Booking")
seat_booking_window.geometry("800x600")
label_seat_booking = tk.Label(seat_booking_window, text="Select
Your Seats", font=("Helvetica", 20))
label_seat_booking.grid(row=0, column=0, columnspan=7,
pady=20)

def book_seat(row, col):


if seats[row * num_cols + col]["bg"] == "green":
seats[row * num_cols + col].configure(bg="red")
else:
seats[row * num_cols + col].configure(bg="green")

num_rows = 7
num_cols = 7

seats = [] # 2D list to store seat buttons

for row in range(num_rows):


for col in range(num_cols):
seat = tk.Button(seat_booking_window, text=f"Seat {row *
num_cols + col + 1}", width=3, height=1, bg="green", command=lambda
r=row, c=col: book_seat(r, c))
seat.grid(row=row + 1, column=col + 1, padx=5, pady=5) #
Adjusted column index
seats.append(seat)

selected_seats = [] # List to store selected seat numbers

def confirm_selection():
nonlocal selected_seats
selected_seats = [f"Seat {r * num_cols + c + 1}" for r in
range(num_rows) for c in range(num_cols) if seats[r * num_cols + c]
["bg"] == "red"]
if not selected_seats:
messagebox.showinfo("Selection Confirmation", "No seats
selected.")
else:
messagebox.showinfo("Selection Confirmation", f"Selected
Seats for {selected_movie} on {selected_date} at {selected_time}:\n" +
"\n".join(selected_seats))
open_payment_screen()

# Create a "Confirm Selection" button


confirm_button = tk.Button(seat_booking_window, text="Confirm
Selection", command=confirm_selection)
confirm_button.grid(row=num_rows + 1, column=0, columnspan=7,
pady=20) # Adjusted row index

def open_payment_screen():
payment_window = tk.Toplevel(seat_booking_window)
payment_window.title("Payment")
payment_window.geometry("400x300")

label_payment = tk.Label(payment_window, text="Payment


Details", font=("Helvetica", 20))
label_payment.pack(pady=20)

label_amount = tk.Label(payment_window, text="Total


Amount:")
label_amount.pack()

total_amount = len(selected_seats) * 10 # Assuming each seat


costs $10
label_amount_value = tk.Label(payment_window, text=f"$
{total_amount}")
label_amount_value.pack()

def process_payment():
messagebox.showinfo("Payment Successful", "Payment
completed successfully. Enjoy the movie!")
payment_window.destroy()

# Create a "Process Payment" button


payment_button = tk.Button(payment_window, text="Process
Payment", command=process_payment)
payment_button.pack(pady=20)

ok_button = tk.Button(movie_selection_window, text="OK",


command=open_seat_booking_screen)
ok_button.pack(pady=20)

# Function to open the registration screen


def open_registration_screen():
registration_window = tk.Toplevel(root)
registration_window.title("Register")
registration_window.geometry("400x300")
label_register = tk.Label(registration_window, text="Register",
font=("Helvetica", 24))
label_register.pack(pady=20)

label_new_username = tk.Label(registration_window, text="New


Username:")
label_new_password = tk.Label(registration_window, text="New
Password")
entry_new_username = tk.Entry(registration_window)
entry_new_password = tk.Entry(registration_window, show="*")
label_new_username.pack()
entry_new_username.pack()
label_new_password.pack()
entry_new_password.pack()

def register_user():
new_username = entry_new_username.get()
new_password = entry_new_password.get()

try:
# Connect to the MySQL database
db = mysql.connector.connect(
host="localhost",
user="root",
password="",
database="MovieTicketDB"
)
cursor = db.cursor()
# Check if the new username already exists in the database
query = "SELECT * FROM users WHERE username=%s"
cursor.execute(query, (new_username,))
result = cursor.fetchone()

if result:
messagebox.showerror("Registration Failed", "Username
already exists.")
else:
# Insert the new user into the database
query = "INSERT INTO users (username, password) VALUES
(%s, %s)"
cursor.execute(query, (new_username, new_password))
db.commit()
messagebox.showinfo("Registration Successful", "Registration
completed successfully.")

db.close()
except mysql.connector.Error as err:
messagebox.showerror("Database Error", f"Error: {err}")
except Exception as e:
messagebox.showerror("Error", f"An error occurred: {e}")

register_button = tk.Button(registration_window, text="Register",


command=register_user)
register_button.pack()

# Create the main window for login


root = tk.Tk()
root.title("Movie Ticket Booking System")
root.geometry("1000x800")

# Create a heading label for login


heading = tk.Label(root, text="Login", font=("Helvetica", 24))
heading.pack(pady=20)

# Create labels and entry widgets for username and password


label_username = tk.Label(root, text="Username:")
label_password = tk.Label(root, text="Password")
entry_username = tk.Entry(root)
entry_password = tk.Entry(root, show="*")
label_username.place(x=400, y=400)
entry_username.place(x=500, y=400)
label_password.place(x=400, y=450)
entry_password.place(x=500, y=450)

# Create a Login button


login_button = tk.Button(root, text="Login", command=login)
login_button.place(x=500, y=500)

# Create a Register button


register_button = tk.Button(root, text="Register",
command=open_registration_screen)
register_button.place(x=600, y=500)

# Run the application


root.mainloop()
Output Screens
Further Development

 Storage of seats in SQL


 Snacks
 Payment screen
Bibliography

 Sumitha Arora Class 11 TextBook


 Sumitha Arora Class 12 TextBook
 https://docs.python.org/3/library/tkinter.html

You might also like