[go: up one dir, main page]

0% found this document useful (0 votes)
33 views39 pages

Class Xii Computer Science Project- Final

Uploaded by

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

Class Xii Computer Science Project- Final

Uploaded by

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

D.A.V.

SCHOOL, PALLIKARANAI

Project File on
VOTER MANAGEMENT SYSTEM
Session- 2024-2025

NAME: SHREYA BALAKRISHNAN

CLASS: XII D

REGISTRATION NO:

Teacher-In-Charge
Ms. G Sivaneswari
D.A.V. SCHOOL – PALLIKARANAI

Name : Roll no :

Class : Regd. No:

CERTIFICATE

Certified that this is a Bonafide report of Computer Science Project work


done by Shreya Balakrishnan during the year 2024 – 2025.

Teacher-In-Charge

Submitted for the Practical Examination in Computer Science (083) at


DAV School Pallikaranai held on …………………………………….

Internal Examiner

External Examiner The Principal


ACKNOWLEDGEMENT

In the accomplishment of this project successfully, many people have


bestowed their blessings and heart pledged support upon me, I take this
opportunity to express my gratitude to all, who have been instrumental
in the successful completion of this project.

I express my thanks to my subject teacher Ms. G Sivaneswari for her


suggestions and critical feedback.

I would also like to thank my parents, friends and all the members who
contributed to this project was vital for the success of the project.
I am grateful for their constant support and help.
CONTENTS

▪ OVERVIEW OF PYTHON 1
➢ Key Features of Python
➢ Applications of Python
▪ OVERVIEW OF MYSQL 3
➢ Key features
➢ Common Uses
▪ HARDWARE AND SOFTWARE 5
REQUIREMENTS
▪ SOURCE CODE 7
▪ OUTPUT 22
▪ TABLES USED IN CODE 27
➢ Voters Table
➢ Candidates Table
➢ Areas Table
▪ FUNCTIONS USED IN CODE 29
➢ create_tables(cursor)
➢ data_insertion(cursor,mycon)
➢ voter_details(cursor, voter_id)
➢ candidate_details(cursor, area_id)
➢ area_details(cursor, area_id)
➢ voters_in_area(cursor, area_id)
➢ number_voters(cursor, area_id)
➢ voter_edit(cursor)
➢ voter_update(cursor)
➢ show_error()
➢ close_connection(cursor)
▪ CONCLUSION 34
▪ BIBILIOGRAPHY 35
Overview of Python

Python is a high-level, interpreted language created by Guido van


Rossum in the late 1980s. It focuses on being easy to read and simple
to use, making it great for both beginners and experts. Its clear and
straightforward syntax lets developers write code more concisely than
in many other languages.

Key Features of Python

▪ Readability and Simplicity


o Python’s syntax is clear and easy to understand, making it
beginner-friendly and improving code maintainability.

▪ Versatile and Cross-Platform:


o Python works on multiple operating systems like Windows,
macOS, and Linux, making it adaptable for various projects.

▪ Strong Community Support


o Python has a vast and active community that provides
numerous tutorials, resources, and forums for support and
learning.

▪ Interpreted Language
o Python executes code line by line, which simplifies testing
and debugging.

1|Page
Applications of Python

• Web Development: Frameworks like Django and Flask make it


easy to build web applications efficiently
• Data Science and Analytics: Libraries like Pandas, NumPy, and
Matplotlib are crucial for data analysis, visualization, and handling
large datasets.
• Machine Learning and AI: Python is widely used for building
machine learning models using powerful libraries like TensorFlow
and Scikit-learn.
• Automation and Scripting: It’s great for automating repetitive
tasks, making it useful for system administration, data processing,
and task automation.
• Game Development: Tools like Pygame help developers create
games quickly and efficiently.

Python's simplicity, versatility, and strong community support


make it an ideal choice for diverse projects, from web development
to data analysis. As you begin working with Python, utilizing its
vast libraries and frameworks will help you create powerful,
efficient solutions. Whether you're a beginner or a seasoned
developer, Python can significantly boost your productivity and
creativity in software development.

2|Page
Overview of MySQL

MySQL is a widely-used, open-source relational database


management system that uses Structured Query Language (SQL)
for managing databases.
It was developed in the mid-1990s by MySQL AB and is now
owned by Oracle Corporation.

Key Features
• Cross-Platform Compatibility: Works on various operating
systems, including Windows, macOS, and Linux.
• Scalability: Supports both small-scale projects and large,
enterprise-level applications.
• High Performance: Optimizes data retrieval and query speed
through techniques like indexing, caching, and partitioning.
• Data Integrity and Security: Ensures data accuracy and offers
robust security measures to protect against unauthorized access.
• Multi-User Access: Allows multiple users to access and modify
data simultaneously.
• Transaction Support: Ensures reliable data operations with
support for ACID (Atomicity, Consistency, Isolation, Durability)
properties.

3|Page
Common Uses
• Web Development: Powers popular content management systems
(CMS) like WordPress, Joomla, and Drupal.
• Web Applications: Frequently used with frameworks like Django,
Laravel, and PHP to build dynamic websites.
• Data Analytics and Reporting: Supports data warehousing and
reporting tools for business intelligence.

Tools and Community Support


• MySQL Workbench: A graphical tool for database design,
administration, and management.
• Extensive Community Resources: Large community support,
with plenty of tutorials, documentation, and forums available for
assistance.

Advantages
• Ease of Use: Simple to install and set up, even for beginners.
• Flexibility: Suitable for a wide range of projects, from small
websites to large-scale data applications.
• Cost-Effective: Being open-source, it is free to use, making it an
economical option for developers.

4|Page
Hardware and Software Requirements

Hardware Requirements
1. Computer: Any computer or laptop with at least an Intel i3 or
AMD Ryzen 3 processor is enough, as the program is not very
demanding.
2. RAM: A minimum of 4 GB is recommended, though 8 GB or
more would ensure better performance, especially if other
applications are running.
3. Storage: Basic storage (at least 500 MB) is needed for Python,
required libraries, and the votermanagementsystem.py file where
data is stored.
4. Input Devices: A keyboard and mouse are required to enter and
manage data within the program.
5. Display: Any standard monitor or laptop screen will work for
viewing program output and navigating the menu.

5|Page
Software Requirements

1. Operating System:
o Compatible with Windows, macOS, or Linux. Python and its
libraries, like pickle, are supported on all these platforms.
2. Python Environment:
o Python: Version 3.x (preferably 3.7 or newer for the latest
features and library compatibility).
o Python Standard Library: The tkinter module, part of
Python's standard library, is used here for creating graphical
user interfaces (GUIs). No additional installation is needed
if Python is already installed.
3. IDE:
o IDEs: Tools like PyCharm, VS Code, or IDLE can make
coding easier with features like debugging and code
suggestions.
4. Command-Line Interface (CLI):
o A command-line tool, such as Command Prompt (Windows),
Terminal (macOS or Linux), or a terminal within an IDE, is
needed to run the program if not using an IDE.
5. Database System:
o To managing datasets, a database like MySQL is used. Even
SQLite can be used. Both databases work well with Python
and offer more features and data handling capabilities.

6|Page
SOURCE CODE

import mysql.connector as mys


from tkinter import *
from tkinter import messagebox
mycon=mys.connect(host='localhost',user='root',
passwd='root',database='votermanagementsystem')
cursor=mycon.cursor()

#to create the tables


def create_tables(cursor):
create_voters_table = "CREATE TABLE IF NOT
EXISTS voters (voter_id INT PRIMARY KEY
AUTO_INCREMENT,\
name VARCHAR(40),age INT, gender
VARCHAR(6),area_id INT(5) NOT NULL);"
create_areas_table = """CREATE TABLE IF NOT
EXISTS areas (area_id INT(5) PRIMARY KEY,
area_name VARCHAR(20),
candidate_count INT);"""
create_candidates_table = """
CREATE TABLE IF NOT EXISTS candidates (
candidate_name VARCHAR(40),
area_id INT(5),
7|Page
area_name VARCHAR(20),
age INT(2),
party_name VARCHAR(20));"""

cursor.execute(create_candidates_table)
cursor.execute(create_areas_table)
cursor.execute(create_voters_table)

#to insert data into the table


def data_insertion(cursor,mycon):
voter_data = [
('Ramesh Kumar', 34, 'Male', 1),
('Priya Singh', 28, 'Female', 1),
('Amit Shah', 42, 'Male', 2),
('Lakshmi Iyer', 55, 'Female', 2),
('Ravi Patel', 23, 'Male', 3),
('Suman Gupta', 30, 'Female', 3),
('Anil Chatterjee', 47, 'Male', 4),
('Neha Mehta', 39, 'Female', 4),
('Manoj Joshi', 60, 'Male', 5),
('Asha Pillai', 33, 'Female', 5),
('Vikram Sinha', 27, 'Male', 1),
('Sunita Yadav', 36, 'Female', 1),
('Rajesh Reddy', 41, 'Male', 2),
('Meena Desai', 52, 'Female', 2),
('Krishna Verma', 25, 'Male', 3),

8|Page
('Anita Kapoor', 45, 'Female', 3),
('Shyam Narayan', 50, 'Male', 4),
('Kiran Malhotra', 29, 'Female', 4),
('Deepak Sharma', 65, 'Male', 5),
('Rekha Banerjee', 31, 'Female', 5)]
insert_query = "INSERT INTO voters (name,
age, gender, area_id) VALUES (%s, %s, %s, %s);"
cursor.executemany(insert_query,
voter_data)
mycon.commit()
areas_data=[(1, 'Panauti', 4),
(2, 'Bandra', 5),
(3, 'Jayanagar', 3),
(4, 'Raj Lake', 6),
(5, 'Indira Nagar', 2)]
insert_query = "INSERT INTO areas (area_id,
area_name, candidate_count) VALUES (%s, %s,
%s);"
cursor.executemany(insert_query,
areas_data)
mycon.commit()
candidates_data = [
('Rahul Mehra', 1, 'Panauti', 45,
'National Party'),
('Priya Kapoor', 2, 'Bandra', 37,
'People\'s Alliance'),

9|Page
('Arjun Rao', 3, 'Jayanagar', 52,
'United Front'),
('Sneha Iyer', 4, 'Raj Lake', 40,
'Progressive Alliance'),
('Vikram Bhatia', 5, 'Indira Nagar',
33, 'National Party'),
('Anita Desai', 1, 'Panauti', 50,
'People\'s Alliance'),
('Ramesh Singh', 2, 'Bandra', 43,
'United Front'),
('Deepa Nair', 3, 'Jayanagar', 39,
'National Party'),
('Suresh Kumar', 4, 'Raj Lake', 55,
'People\'s Alliance'),
('Leela Gupta', 5, 'Indira Nagar', 47,
'Progressive Alliance')]

insert_query = "INSERT INTO candidates


(candidate_name, area_id, area_name, age,
party_name) VALUES (%s, %s, %s, %s, %s);"
cursor.executemany(insert_query,
candidates_data)
mycon.commit()
print("Data inserted successfully into
respective tables.")

10 | P a g e
#Calling the above functions
create_tables(cursor)
data_insertion(cursor,mycon)

#To view voter details


def voter_details(cursor, voter_id):
query = "SELECT * FROM voters WHERE
voter_id = %s"
cursor.execute(query, (voter_id,))
result=cursor.fetchone()
root = Tk()
root.title("Voter Details")
root.geometry("1000x1000")
details_label = Label(root,text=f"VOTER
DETAILS\n\n"f"ID: {result[0]}\n"f"Name:
{result[1]}\n"f"Age: {result[2]}\n"f"Gender:
{result[3]}\n"f"Area ID: {result[4]}",
font=("Times New Roman", 20),
bg="#3B1C32",fg="#FCF596",justify="left",
padx=20, pady=20)
details_label.pack(pady=50)
root.mainloop()

#To view candidate details


def candidate_details(cursor, area_id):
query = "SELECT * FROM candidates WHERE

11 | P a g e
area_id = %s"
cursor.execute(query, (area_id,))
i=cursor.fetchall()
root = Tk()
root.title('Candidate Details')
root.geometry("10000x10000")
count=1
for result in i:
d=f"NAME: {result[0]}\nArea ID:
{result[1]}\nArea Name: {result[2]}\nAge: \
{result[3]}\nParty name: {result[4]}"
details_label = Label(root,text =
f"CANDIDATE DETAILS\n\nCandidate {count}
details \n{d}",font=("Times New Roman",
20),bg="#3B1C32",fg="#FCF596", justify="left",
padx=50, pady=50)
details_label.pack( side = TOP)
count+=1
root.mainloop()

#To view area details


def area_details(cursor, area_id):
query = "SELECT * FROM areas WHERE area_id
= %s"
cursor.execute(query, (area_id,))

12 | P a g e
result=cursor.fetchone()
root = Tk()
root.title('Area Details')
root.geometry("1000x1000")
d=f"Area ID: {result[0]}\nArea Name:
{result[1]}\nCandidate Count: {result[2]}"
label = Label(root,text = f"AREA
DETAILS\n\n {d}",
font=("Times New Roman",
20),bg="#3B1C32",fg="#FCF596",
justify="left", padx=50,
pady=50)
label.pack( side = TOP)
root.mainloop()

#To view all the voters in an area


def voters_in_area(cursor, area_id):
query = "SELECT * FROM voters WHERE area_id
= %s"
cursor.execute(query, (area_id,))
i=cursor.fetchall()
root = Tk()
roo1=Tk()
root.title('Areawise Voter Details')
root.geometry("1000x700")
roo1.geometry("1000x1000")

13 | P a g e
count=1
for result in i:
d=f"ID: {result[0]}\nName:
{result[1]}\nAge: {result[2]}\nGender:
{result[3]}\nArea ID: {result[4]}"
def fun(d):
label = Label(roo1,text = f"VOTERS
IN AN AREA\n\n {d}",
font=("Times New Roman",
10),bg="#3B1C32",fg="#FCF596",
justify="left", padx=20,
pady=20)
label.pack( side = TOP)
btn1 = Button(root,text = f"Voter
{count} details",font=("Papyrus",
24),bg="green",fg="white",padx=10,pady=10,comma
nd=lambda d=d: fun(d))
btn1.pack( side = TOP)
count+=1
root.mainloop()

#To see the number of voters in an area


def number_voters(cursor, area_id):
query = """SELECT COUNT(a.voter_id),
b.area_name
FROM voters AS a

14 | P a g e
JOIN areas AS b ON a.area_id =
b.area_id
WHERE a.area_id = %s
GROUP BY b.area_name;"""
cursor.execute(query, (area_id,))
t = cursor.fetchone()
if t:
message = f'The number of voters in
{t[1]} with ID {area_id} is {t[0]}'
else:
message = f'No voters found for area
with ID {area_id}'
root = Tk()
root.title("Voter Count")
root.geometry("1000x700")
label = Label(root, text = f"NUMBER OF
VOTERS IN AN AREA\n\n {message}",
font=("Times New Roman",
20),bg="#3B1C32",fg="#FCF596",
justify="left", padx=20,
pady=20)
label.pack(pady=20)
root.mainloop()

#To edit the voter details


def voter_edit(cursor):

15 | P a g e
iD=int(input("Enter voter ID: "))
query='select * from voters where
voter_id=%s'
cursor.execute(query,(iD,))
old=cursor.fetchone()
name=input('Enter name: ')
age=int(input('Enter age: '))
gender=input('Enter gender: ')
areaID=int(input('Enter area ID: '))
update_query = """UPDATE voters SET name =
%s, age = \
%s, gender = %s, area_id = %s WHERE voter_id =
%s;"""
cursor.execute(update_query, (name, age,
gender, areaID, iD))
mycon.commit()
query='select * from voters where
voter_id=%s'
cursor.execute(query,(iD,))
new=cursor.fetchone()
root = Tk()
root.title("Voter Count")
root.geometry("1000x1000")
message=f'Old Details:{old} \nNew Details:
{new}'
label = Label(root, text=message,

16 | P a g e
font=("Times New Roman",
20),bg="#3B1C32",fg="#FCF596",
justify="left", padx=20,
pady=20)
label.pack(pady=20)
root.mainloop()
print("Voter details edited successfully.")

#To add new voter details


def voter_update(cursor):
name=input('Enter name: ')
age=int(input('Enter age: '))
gender=input('Enter gender: ')
areaID=int(input('Enter area ID: '))
voter_data=[name,age,gender,areaID]
insert_query = "INSERT INTO voters (name,
age, gender, area_id) VALUES (%s, %s, %s, %s);"
cursor.execute(insert_query, voter_data)
mycon.commit()
root = Tk()
root.title("successful")
root.geometry("1000x1000")
message = 'Voter deatail updated
successfully!'
label = Label(root, text=message,
font=("Times New Roman",

17 | P a g e
20),bg="#3B1C32",fg="#FCF596",
justify="left", padx=20,
pady=20)
label.pack(pady=20)
root.mainloop()

#To display any error message


def show_error():
root = Tk()
root.title("ERROR!")
root.geometry("400x200")
label = Label(root, text='INVALID INPUT',
font=("Times New Roman",
20),bg="#3B1C32",fg="#FCF596",
justify="left", padx=20,
pady=20)
label.pack(pady=20)
root.mainloop()

#To close the mysql connection


def close_connection(cursor):
self.cursor.close()
self.connection.close()
print('\t********MENU********')
print('Enter 1 to view voter details')
print('Enter 2 to view candidate details')

18 | P a g e
print('Enter 3 to view area details')
print('Enter 4 to view all voters in area')
print('Enter 5 to view the number of voters in
an area ')
print('Enter 6 to edit voter details')
print('Enter 7 to insert new voter details')

while True:
ch=int(input('Enter Choice: '))
if ch==1:
vID=int(input('Enter voter ID: '))
if isinstance(vID, int):
t=voter_details(cursor,vID)
print('Voter details displayed
successfully')
else:
show_error(message)
elif ch==2:
areaID=int(input('Enter area ID: '))
if isinstance(areaID, int):
candidate_details(cursor, areaID)
print('Candidate details displayed
successfully')
else:
show_error(message)
elif ch==3:

19 | P a g e
areaID=int(input('Enter area ID: '))
if isinstance(areaID, int):
area_details(cursor, areaID)
print('Area details displayed
successfully')
else:
show_error(message)
elif ch==4:
area_id=int(input('Enter area ID: '))
if isinstance(area_id, int):
voters_in_area(cursor, area_id)
print('Details of all voters in an
area displayed successfully')
else:
show_error(message)

elif ch==5:
area_id=int(input('Enter Area ID: '))
if isinstance(area_id, int):
number_voters(cursor,area_id)
print('The number of voters in an
area displayed successfully')
else:
show_error(message)
elif ch==6:
voter_edit(cursor)

20 | P a g e
print('Voter details edited
successfully')
elif ch==7:
voter_update(cursor)
('Added voter details successfully')
else:
show_error()
choice=input('DO YOU WANT TO CONTINUE?
(Y/N)')
if choice in 'Nn':
print('Thank You')
break

21 | P a g e
OUTPUT

• To view voter details

• To view candidate details

22 | P a g e
• To view voter details

• Area-wise voter details

23 | P a g e
• To view number of voters in an area

24 | P a g e
• To view voter details

• To add voter details

25 | P a g e
• Error message

26 | P a g e
TABLES USED
• Voters Table

27 | P a g e
• Candidates Table

• Areas Table

28 | P a g e
FUNCTIONS USED IN THE CODE

▪ create_tables(cursor)
The create_tables(cursor) function sets up three
database tables (voters, areas, and candidates) for a
voting system. It uses the provided cursor to execute CREATE
TABLE statements, ensuring the tables are only created if they
don’t already exist. These tables store details about voters,
electoral areas, and candidates, helping structure data for an
election management application.

▪ data_insertion(cursor,mycon)
The data_insertion(cursor, mycon) function
populates the database tables (voters, areas, and
candidates) with predefined data for an election management
system. It uses executemany() to efficiently insert multiple
records into each table and commits the changes to the database.
This function is crucial for setting up initial data, enabling the
application to operate with sample entries for testing or
demonstration purposes.

29 | P a g e
▪ voter_details(cursor, voter_id)
The voter_details(cursor, voter_id) function
retrieves and displays the details of a specific voter from the
database using a graphical interface created with tkinter. It fetches
data based on the given voter_id and shows it in a pop-up message
box when a button is clicked. This function helps users easily
access and view individual voter information within a user-
friendly interface.

▪ candidate_details(cursor, area_id)

The candidate_details(cursor, area_id) function


fetches and displays details of all candidates from a specified area
using tkinter. It retrieves candidates based on the given
area_id and creates a button for each candidate. Clicking a
button shows the candidate's details (name, area, age, party) in a
pop-up message. This function is useful for quickly accessing
candidate information in a user-friendly GUI format.

30 | P a g e
▪ area_details(cursor, area_id)

The area_details(cursor, area_id) function is


designed to retrieve and display information about a specific area
from the database using a graphical interface. It fetches data based
on the provided area_id and displays it using tkinter. When
the button is clicked, it shows the area’s ID, name, and the number
of candidates in a pop-up message box. This makes it easy for
users to quickly view area details in a simple, interactive way.

▪ voters_in_area(cursor, area_id)

The voters_in_area(cursor, area_id) function


retrieves and displays a list of all voters within a specific area using
a graphical interface built with tkinter. It fetches voters based
on the provided area_id and creates a button for each voter.
Clicking a button displays the voter's details (ID, name, age,
gender, area) in a pop-up message. This function is useful for
viewing area-specific voter information in an organized,
interactive way.

31 | P a g e
▪ number_voters(cursor, area_id)

The number_voters(cursor, area_id) function


calculates and displays the total number of voters in a specific area
using tkinter. It executes a query to count the voters linked to
the given area_id and shows the area’s name and voter count in
a label on a graphical window. If no voters are found, it displays a
corresponding message. This function helps users quickly view the
voter count for any area in an interactive manner.

▪ voter_edit(cursor)

The voter_edit(cursor) function allows the editing of a


specific voter's details in the database. It first retrieves the existing
details of the voter using their voter_id. The user is prompted
to enter new details (name, age, gender, and area ID), and the
function updates the record in the voters table. After the update,
the function displays both the old and new details in a graphical
window using tkinter. This function is useful for modifying
voter information in an interactive and visual way.

32 | P a g e
▪ voter_update(cursor)

The voter_update(cursor) function is designed to add a


new voter’s details into the database. It prompts the user to input
the voter's name, age, gender, and area ID. The function then
inserts the entered data into the voters table. After the successful
insertion, a confirmation message is displayed in a graphical
window using tkinter. This function is useful for adding new
voters to the system interactively.

▪ show_error()

The show_error() function is used to display an error message


in a graphical window using tkinter. When invoked, it creates
a simple window with the title "ERROR!" and shows the message
"INVALID INPUT" in white text on a dark background. This
function is useful for alerting users to input errors or invalid
actions in an application.

▪ close_connection(cursor)

The close_connection(cursor) function is used to close


the MySQL database connection and the cursor object after
completing database operations. By calling this function, it ensures
that resources are properly released, preventing potential memory
leaks or unnecessary open connections. This is an important step
in maintaining efficient database interactions and ensuring the
system is secure.

33 | P a g e
CONCLUSION

The Voter Management System is a simple yet effective project


designed to manage voter and election data efficiently. It allows users to
view, update, and organize details about voters, candidates, and areas,
making it easier to handle election processes. The system reduces
manual errors, saves time, and ensures information is accurate and
accessible.

This project has room for improvement. Adding features like better
security, such as password protection or biometric verification, could
make it safer. Turning it into a website would let people access it from
anywhere. Other upgrades, like adding charts for data analysis or
support for multiple languages, could make it more useful for diverse
users.
In conclusion, the Voter Management System is a great starting point
for understanding how technology can improve election management. It
meets its current goals but also shows how future updates could make it
even better. This project highlights the importance of organized systems
and opens up ideas for innovation.

34 | P a g e
BIBILIOGRAPHY

Computer Science with Python - Sumita Aurora Class XII


https://docs.python.org/3/library/tkinter.html#module-tkinter
https://www.geeksforgeeks.org/python-mysql/

35 | P a g e

You might also like