0% found this document useful (0 votes)
103 views64 pages

CS Poroj

This document is a project report for a Quiz Application developed using Python and MySQL. It includes a cover page with the project title, student and school details. It then provides an acknowledgements section thanking those who helped with the project. The contents page outlines the main sections of the report including the introduction, objectives, theoretical background, system design, source code, outputs, user manual and conclusion. It appears the project involved developing a graphical user interface for a quiz application using Python Tkinter connected to a MySQL database to store and retrieve quiz questions, answers and scores.

Uploaded by

Swedha R
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)
103 views64 pages

CS Poroj

This document is a project report for a Quiz Application developed using Python and MySQL. It includes a cover page with the project title, student and school details. It then provides an acknowledgements section thanking those who helped with the project. The contents page outlines the main sections of the report including the introduction, objectives, theoretical background, system design, source code, outputs, user manual and conclusion. It appears the project involved developing a graphical user interface for a quiz application using Python Tkinter connected to a MySQL database to store and retrieve quiz questions, answers and scores.

Uploaded by

Swedha R
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/ 64

Project

COMPUTER SCIENCE

By: Hariduthram.P.S
Class: XII
Roll no:
SSVM WORLD SCHOOL
Department of Computer Science
Bonafide Certificate
I hereby certify that this project entitled Quiz Application bonafide
work done by Hariduthram.P.S.

Register No: .

In the department of Computer science of SSVM WORLD SCHOOL


under my supervision during the academic year 2022-2023 .

Date . Signature of the teacher in charge

Signature of the Principal

Submitted for practical examination held in the school


centre on .

Signature of School seal Signature of

Internal Examiner External Examiner


ACKNOWLEDGEMENT

The successful completion of any task would be incomplete without crediting

the names of those who helped to make it possible. I hereby take this

opportunity to express my gratitude, gratefulness and respect in few words to

all those who backed me in completion of this project. I express my special

thanks to my

Parents, my Correspondent Mrs. Manimekalai Mohan, my Principals

Mrs. Nimitha Pramod and Mrs. Radhika, the teachers of the Computer

science department, mainly Mr. Mujibullah and Mrs. Nirmala and who

gave me ample help and support to pursue and complete the project on this

topic.

Secondly I would like to thank CBSE for giving me such an opportunity without

which I would not have been able to do such a project. I would also like to thank

my friends who helped me in my research and execution and it is with their

supportiveness that I could complete this venture within the limited time frame.

My hearty thanks to the aforementioned.


Sno: CONTENTS Pg.
NO:
1 INTRODUCTION 5

2 OBJECTIVE AND SCOPE OF THE 6


PROJECT
3 THEORETICAL BACKGROUND 7

4 SYSTEM IMPLEMENTATION 14

5 SYSTEM DESIGN & DEVELOPMENT 15

6 SOURCE CODE 20

7 OUTPUTS 42

8 USER MANUAL 62

9 CONCLUSION 63

10 BIBLIOGRAPHY 64
INTRODUCTION:

The ‘MCQ Quiz Application’ project developed to overcome the time


consuming problem of manual system. Apart from that in current system,
checking the answer sheets after taking test, waste the examiners time, so this
application will check the correct answer and save the examiner time and
carry the examination in an effective manner. The users which are use this
system don’t need to high computing knowledge and also system will inform
them while entering invalid data.

The Quiz Application (Back-end) primarily consists of a computerized


database, that stores a collection of inter-related tables for a specific purpose,
capable of producing different reports that are particular to the user. An
application program (Front-end) is tied with the database for easy access and as user
interface to the database. Using a front-end, we can store, retrieve and manage all
information in the most optimum and suitable manner.

This software, being simple in design and working, does not require much
training to users; it can be used as the right tool to check one’s eligibility in quiz
programs.

For the coding and design of the Project, Python IDLE, a powerful front-end
tool is used for getting Graphical User Interface (GUI) based integrated platform
and coding simplicity. MySQL, a powerful, open source RDBMS, is used as
back-end as per requirement and suitability of the CBSE curriculum of
Computer science course.

5
OBJECTIVE AND SCOPE OF THE PROJECT :

The objective of this project is to let the students apply the programming knowledge into a
real- world situation/problem and exposed the students how programming skills helps in
developing a good software.
 Write programs utilizing modern software tools.
 Apply object oriented programming principles effectively when developing
small to medium sized projects.
 Write effective procedural code to solve small to medium sized problems.
 Students will demonstrate a breadth of knowledge in computer science, as
exemplified in the areas of systems, theory and software development.
 Students will demonstrate ability to conduct a research or applied Computer
Science project, writing and presentation skills which exemplify scholarly style in
computer science.

The software system is expected to do the following


functionality:
 Design and implement a quiz application with a graphical user interface (GUI) using Python
Tkinter. The GUI could include elements such as text labels, buttons, and entry fields to allow the
user to interact with the application.

• Connect the quiz application to a MySQL database to store and retrieve data such as quiz
questions, answers, and scores. This could involve creating a database schema and writing SQL
queries to manipulate the data.

• Implement features such as displaying quiz questions and multiple choice answers, tracking
the user's progress through the quiz, and calculating the user's score at the end of the quiz.

• Allow the user to create and edit quiz questions and answers using the application, potentially
requiring additional GUI elements and functionality to manage the data.

• Implement security measures to protect the database and ensure data integrity, such as using
prepared statements and sanitizing user input.

• Test and debug the application to ensure it is functioning correctly and meets the desired
specifications.

6
THEORETICAL BACKGROUND
What is Database?
Database is a systematic collection of data. It supports storage and manipulation of data,
makes data management easy.

What is RDBMS?
RDBMS stands for Relational Database Management System. RDBMS is the basis for
SQL, and for all modern database systems like MS SQL Server, IBM, DB2, Oracle,
MySQL and Microsoft Access.

A Relational database management system (RDBMS) is a database management system


(DBMS) that is based on the relational model as introduced by E.F.Codd.

What is a table?
The data in an RDBMS is stored in database objects which are called as tables. This
table is basically a collection of related data entries and it consists of numerous columns
and rows.

Example of a table:

All the information is stored in the form of tables.

7
ABOUT PYTHON IDLE
Python is a high-level, interpreted and general purpose dynamic
programming language that focuses on code readability.

The syntax in Python helps the programmers to do coding in fewer steps as


compared to Java or C++. The language founded in the year 1991 by the
developer Guido Van Rossum has the programming easy and fun to do.

The Python is widely used in bigger organisations because of its multiple


programming paradigms. They usually involve imperative and object-
oriented functional programming.

It has a comprehensive and large standard library that has automatic


memory management and dynamic features.

IDLE (Integrated Development and Learning Environment) is an integrated


development environment (IDE) for Python. The Python installer for
Windows and MAC contains the IDLE module by default.

IDLE is intended to be a simple IDE and suitable for beginners, especially


in an educational environment. To that end, it is cross-platform, and avoids
feature clutter.

According to the included README, its main features are:

• Multi-window text editor with syntax highlighting,


auto completion, smart indent and other.

• Python shell with syntax highlighting.

• Integrated debugger with stepping, persistent


breakpoints, and call stack visibility.

8
Python has topped the charts in the recent years over other programming
languages like C, C++ and Java and is widely used by the programmers.

The language has undergone a drastic change since its release 25 years ago
as many add-on features are introduced. The Python 1.0 had the module
system of Modula-3 and interacted with Amoeba Operating System with
varied functioning tools.

Python 2.0 introduced in the year 2000 had features of garbage collector and
Unicode Support. Python 3.0 introduced in the year 2008 had a constructive
design that avoids duplicate modules and constructs.

With the added features, now the companies are using Python
3.5 and a few later releases.

Some of the characteristics of python that attract big


companies to use this programming language are:
• Interactive

• Interpreted

• Modular

• Dynamic

• Object-oriented

• Portable

• High level

• Extensible in C++ & C

9
Some of the advantages of python are:
• Extensive Support Libraries

• Integration Feature

• Improved Programmer’s Productivity

Limitations or Disadvantages of Python:


• Difficulty in Using Other Languages

• Weak in Mobile Computing

• Gets Slow in Speed

• Run-time Errors

• Under developed Database Access Layers

10
ABOUT TKINTER IN PYTHON
The Tkinter module (“Tk interface”) is the standard Python interface to the Tk GUI
toolkit from Scripts (formerly developed by Sun Labs).

Both Tk and Tkinter are available on most Unix platforms, as well as on Windows and
Macintosh systems. Starting with the 8.0 release, Tk offers native look and feel on
all platforms.

Tkinter consists of a number of modules. The Tk interface is provided by a binary


extension module named _tkinter. This module contains the low-level interface
to Tk, and should never be used directly by application programmers.

It is usually a shared library (or DLL), but might in some cases be statically linked with
the Python interpreter.

The public interface is provided through a number of Python modules. The most
important interface module is the Tkinter module itself.

To use Tkinter, all you need to do is to import the Tkinter module:

“Import Tkinter”

Or, more often:

“from Tkinter import *”

The Tkinter module only exports widget classes and associated constants, so you can
safely use the from-in form in most cases. If you prefer not to, but still want to save
some typing, you can

use import-as: "Import Tkinter as Tk”

Tkinter is the standard GUI library for Python. Python when combined with Tkinter
provides a fast and easy way to create GUI applications. Tkinter provides a
powerful object-oriented interface to the Tk GUI toolkit.

Creating a GUI application using Tkinter is an easy task. All you need to do

is perform the following steps −

• Import the Tkinter module.

• Create the GUI application main window.

• Add one or more of the above-mentioned widgets to the GUI application.

• Enter the main event loop to take action against each event triggered by the user.

11
ABOUT MYSQL
MySQL is an Oracle-backed open source relational database management system
(RDBMS) based on Structured Query Language (SQL). MySQL runs on virtually all
platforms, including Linux, UNIX, Windows and MAC.

Although it can be used in a wide range of applications, MySQL is most often


associated with web applications and online publishing.

MySQL is a fast, easy-to-use RDBMS being used for many small and big businesses.
MySQL is developed, marketed and supported by MySQL AB, which is a Swedish
company.

MySQL is becoming so popular because of many good reasons:

1. Own specific environments MySQL is released under an open-source


license. So you have nothing to pay to use it.

2. MySQL is a very powerful program in its own right. It handles a large


subset of the functionality of the most expensive and powerful database packages.

3. MySQL uses a standard form of the well-known SQL data language.

4. MySQL works on many operating systems and with many languages


including PHP, PERL, C, C++, JAVA, etc.

5. MySQL works very quickly and works well even with large data sets.

6. MySQL is very friendly to PHP, the most appreciated language for web
development. MySQL supports large databases, up to 50 million rows or more in a
table. The default file size limit for a table is 4GB, but you can increase this (if
your operating system can handle it) to a theoretical limit of 8 million terabytes
(TB).

7. MySQL is customisable. The open-source GPL license allows


programmers to modify the MySQL software to fit their desire.

In this project MySQL is used as a back end.

12
MySQL in python can be used by:
1. Connecting to the database.

2. Creating an object for your database.

3. Executing the SQL query.

4. Fetching records from the result.


Informing the Database if you make any changes in the table.

13
SYSTEM IMPLEMENTATION
THE HARDWARE USED:
PC with INTEL® CORE™ with installed RAM of 16GB

System type: 64-Bit operating system, x64 based processor Intel


core i7 10th Gen

THE SOFTWARE USED:


• Microsoft windows 11 as operating system

• Python IDLE 3.9.5 as Front end

• Used VS Code as compiler

• MySQL as Back end server with database for testing

• Libre Office for documentation.

14
SYSTEM DESIGN & DEVELOPMENT

Table Design:
The database of Quiz application contains 9 tables. The
tables are to minimize the redundancies of data. The
tables and their structure are given below:

Table Descriptions:

Table Name: admin

15
Table Name: questions

Table Name: answers

16
Table Name: correct_answers

Table Name: score

17
Table Name: user

Table Name: user_correct_answers

18
Table Name: user_incorrect_answers

Table Name: user_total_score

19
SOURCE CODE

#quiz with tkinter and mysql


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

#connect to mysql
mydb = mysql.connector.connect(
host="localhost",
user="root",
passwd="root",
database="quiz"
)

mycursor = mydb.cursor()

mycursor.execute("CREATE DATABASE IF NOT EXISTS quiz")


mycursor.execute("USE quiz")
mycursor.execute("CREATE TABLE IF NOT EXISTS questions (id
INT AUTO_INCREMENT PRIMARY KEY, question
VARCHAR(255))")
mycursor.execute("CREATE TABLE IF NOT EXISTS answers (id
INT AUTO_INCREMENT PRIMARY KEY, answer1
VARCHAR(255), answer2 VARCHAR(255), answer3
VARCHAR(255), answer4 VARCHAR(255))")
mycursor.execute("CREATE TABLE IF NOT EXISTS
correct_answers (id INT AUTO_INCREMENT PRIMARY KEY,
correct_answer VARCHAR(255))")
mycursor.execute("CREATE TABLE IF NOT EXISTS score (id INT
AUTO_INCREMENT PRIMARY KEY, score INT)")
mycursor.execute("CREATE TABLE IF NOT EXISTS user (id INT
20
AUTO_INCREMENT PRIMARY KEY, user VARCHAR(255))")

mycursor.execute("CREATE TABLE IF NOT EXISTS


user_correct_answers (id INT , user_correct_answers
VARCHAR(255))")
mycursor.execute("CREATE TABLE IF NOT EXISTS
user_incorrect_answers (id INT , user_incorrect_answers
VARCHAR(255))")
mycursor.execute("CREATE TABLE IF NOT EXISTS admin (name
VARCHAR(50), id INT(5) PRIMARY KEY)")
mycursor.execute("CREATE TABLE IF NOT EXISTS
user_total_score(id INT , user_total_score VARCHAR(5) )")

def add_defaultques() :

#questions in database
#1
mycursor.execute("INSERT IGNORE INTO questions values
(NULL,'What is the other name of Salt Lake Stadium ?')")
mycursor.execute("INSERT IGNORE INTO answers
values(NULL,'[A] Yuba Bharti Stadium','[B] Bharat Bharti
Stadium','[C] Eden Gardens','[D] Kolkata Stadium')")
mycursor.execute("INSERT IGNORE INTO correct_answers
values (NULL,'[A] Yuba Bharti Stadium')")
mycursor.execute("INSERT IGNORE INTO score
values(NULL,1)")

#2
mycursor.execute("INSERT IGNORE INTO questions values
(NULL,'Who among the following is first Indian to win an individual
gold medal at any Olympic Games?')")
mycursor.execute("INSERT IGNORE INTO answers values
(NULL,'[A] Abhinav Bindran','[B] Muhammad Aslam','[C]
21
Rajyavardhan Singh Rathode','[D] Mohammed Shahid')")
mycursor.execute("INSERT IGNORE INTO correct_answers
values(NULL,'[A] Abhinav Bindran')")
mycursor.execute("INSERT IGNORE INTO score
values(NULL,1)")

#3
mycursor.execute("INSERT IGNORE INTO questions
values(NULL,'Who has designed the trophy of FIFA Womens World
Cup?')")
mycursor.execute("INSERT IGNORE INTO answers
values(NULL,'[A] William Sawaya','[B] Formiga','[C] Marta','[D]
Sun Wen')")
mycursor.execute("INSERT IGNORE INTO correct_answers
values(NULL,'[A] William Sawaya')")
mycursor.execute("INSERT IGNORE INTO score
values(NULL,1)")

#4
mycursor.execute("INSERT IGNORE INTO questions
values(NULL,'Which of the following is awarded to individuals for
promoting education, culture, development and peace through
sport?')")
mycursor.execute("INSERT IGNORE INTO answers values
(NULL,'[A] Olympic Cup','[B] Olympic Laurel','[C] Olympic
Town','[D] Olympic Order')")
mycursor.execute("INSERT IGNORE INTO correct_answers
values(NULL,'[B] Olympic Laurel')")
mycursor.execute("INSERT IGNORE INTO score values
(NULL,1)")

#5
mycursor.execute("INSERT IGNORE INTO questions
values(NULL,'How far is the service line from the net in tennis?')")
mycursor.execute("INSERT IGNORE INTO answers
22
values(NULL,'[A] 25 feet','[B] 21 feet','[C] 20 feet','[D] 19 feet')")
mycursor.execute("INSERT IGNORE INTO correct_answers
values(NULL,'[B] 21 feet')")
mycursor.execute("INSERT IGNORE INTO score
values(NULL,1)")

#6
mycursor.execute("INSERT IGNORE INTO questions
values(NULL,'Where were the Commonwealth Games 2018 held?')")
mycursor.execute("INSERT IGNORE INTO answers
values(NULL,'[A] New Delhi','[B] Auckland','[C] Gold Coast','[C]
Gold Coast')")
mycursor.execute("INSERT IGNORE INTO correct_answers
values(NULL,'[B] 21 feet')")
mycursor.execute("INSERT IGNORE INTO score
values(NULL,1)")

#7
mycursor.execute("INSERT IGNORE INTO questions
values(NULL,'How many bails are placed on three stumps on either
side of a cricket pitch?')")
mycursor.execute("INSERT IGNORE INTO answers
values(NULL,'[A] 2','[B] 3','[C] 4','[D] 1')")
mycursor.execute("INSERT IGNORE INTO correct_answers
values(NULL,'[A] 2')")
mycursor.execute("INSERT IGNORE INTO score
values(NULL,1)")

#8
mycursor.execute("INSERT IGNORE INTO questions
values(NULL,'What kind of racing event was supported by UCI
ProTour?')")
mycursor.execute("INSERT IGNORE INTO answers
values(NULL,'[A] Road racing','[B] Track racing','[C] Mountain
Biking','[D] BMX')")
23
mycursor.execute("INSERT IGNORE INTO correct_answers
values(NULL,'[A] Road racing')")
mycursor.execute("INSERT IGNORE INTO score
values(NULL,1)")

#9
mycursor.execute("INSERT IGNORE INTO questions values
(NULL,'Where was the first Cricket World Cup held and when?')")
mycursor.execute("INSERT IGNORE INTO answers values
(NULL,'[A] England, 1975','[B] England, 1979','[C] Australia,
1975','[D] Australia, 1979')")
mycursor.execute("INSERT IGNORE INTO correct_answers
values (NULL,'[A] England, 1975')")
mycursor.execute("INSERT IGNORE INTO score
values(NULL,1)")

#10
mycursor.execute("INSERT IGNORE INTO questions values
(NULL,'When did the World Shooting Championships begin?')")
mycursor.execute("INSERT IGNORE INTO answers values
(NULL,'[A] 1897','[B] 1907','[C] 1908','[D] 1915')")
mycursor.execute("INSERT IGNORE INTO correct_answers
values (NULL,'[A] 1897')")
mycursor.execute("INSERT IGNORE INTO score values
(NULL,1)")

mydb.commit()
#add_defaultques()

#function to add questions to the database


def add_questions():
def submit():
question = question_entry.get()
answer1 = answer1_entry.get()
answer2 = answer2_entry.get()
24
answer3 = answer3_entry.get()
answer4 = answer4_entry.get()
correct_answer = correct_answer_entry.get()
score = score_entry.get()

sql = "INSERT INTO questions (question) VALUES (%s)"


val = (question,)
mycursor.execute(sql, val)
mydb.commit()
sql = "INSERT INTO answers (answer1, answer2, answer3,
answer4) VALUES (%s, %s, %s, %s)"
val = (answer1, answer2, answer3, answer4)
mycursor.execute(sql, val)
mydb.commit()
sql = "INSERT INTO correct_answers (correct_answer)
VALUES (%s)"
val = (correct_answer,)
mycursor.execute(sql, val)
mydb.commit()
sql = "INSERT INTO score (score) VALUES (%s)"
val = (score,)
mycursor.execute(sql, val)
mydb.commit()
messagebox.showinfo("Success", "Question added
successfully")
add_questions_window.destroy()
add_questions_window = tk.Tk()
add_questions_window.title("Add Questions")
add_questions_window.geometry("900x700")
add_questions_window.configure(background="light salmon")
question_label = tk.Label(add_questions_window,
text="Question",font=("Arial", 14),bg="grey",fg="white")
question_label.grid(row=0, column=0)

25
question_entry = tk.Entry(add_questions_window ,width=20,
font=("Arial", 14))
question_entry.grid(row=0, column=1)
answer1_label = tk.Label(add_questions_window, text="Answer
1",font=("Arial", 14),bg="grey",fg="white")
answer1_label.grid(row=1, column=0)
answer1_entry = tk.Entry(add_questions_window,width=20,
font=("Arial", 14))
answer1_entry.grid(row=1, column=1)
answer2_label = tk.Label(add_questions_window, text="Answer
2",font=("Arial", 14),bg="grey",fg="white")
answer2_label.grid(row=2, column=0)
answer2_entry = tk.Entry(add_questions_window,width=20,
font=("Arial", 14))
answer2_entry.grid(row=2, column=1)
answer3_label = tk.Label(add_questions_window, text="Answer
3",font=("Arial", 14),bg="grey",fg="white")
answer3_label.grid(row=3, column=0)
answer3_entry = tk.Entry(add_questions_window,width=20,
font=("Arial", 14))
answer3_entry.grid(row=3, column=1)
answer4_label = tk.Label(add_questions_window, text="Answer
4",font=("Arial", 14),bg="grey",fg="white")
answer4_label.grid(row=4, column=0)
answer4_entry = tk.Entry(add_questions_window,width=20,
font=("Arial", 14))
answer4_entry.grid(row=4, column=1)
correct_answer_label = tk.Label(add_questions_window,
text="Correct Answer",font=("Arial", 14),bg="grey",fg="white")
correct_answer_label.grid(row=5, column=0)
correct_answer_entry =
tk.Entry(add_questions_window,width=20, font=("Arial", 14))
correct_answer_entry.grid(row=5, column=1)
score_label = tk.Label(add_questions_window,
text="Score",font=("Arial", 14),bg="grey",fg="white")
26
score_label.grid(row=6, column=0)
score_entry = tk.Entry(add_questions_window,width=20,
font=("Arial", 14))
score_entry.grid(row=6, column=1)
submit_button = tk.Button(add_questions_window,
text="Submit",bg="green", fg="white",
command=submit,font=("Arial", 14))
submit_button.grid(row=7, column=0)
add_questions_window.mainloop()
adminMenu()

#function to add users to the database


def add_users():
def submit():
user = user_entry.get()
val=user
sql = "INSERT INTO user (user) VALUES ('{}')".format(val)
mycursor.execute(sql)
mydb.commit()
messagebox.showinfo("Success", "User added successfully")
add_users_window.destroy()
add_users_window = tk.Tk()
add_users_window.title("Add User")
add_users_window.geometry("900x700")
add_users_window.configure(background="light salmon")
user_label = tk.Label(add_users_window,
text="User",font=("Arial", 20),bg="grey",fg="white")
user_label.grid(row=0, column=0)
user_entry = tk.Entry(add_users_window,font=("Arial", 20))
user_entry.grid(row=0, column=1)
submit_button = tk.Button(add_users_window,
text="Submit",bg="green", fg="white",
command=submit,font=("Arial", 20))
submit_button.grid(row=1, column=0)
27
add_users_window.mainloop()

#function to display user total score to the database


def add_user_total_score():
sql = "select * from user_total_score"
mycursor.execute(sql)
add_user_incorrect_answers_window = tk.Tk()
add_user_incorrect_answers_window.title("Display User total
score")
add_user_incorrect_answers_window.geometry("600x600")

add_user_incorrect_answers_window.configure(background="cadetb
lue4")
x = mycursor.fetchall()

frame4=Frame(add_user_incorrect_answers_window,height=700,wid
th=1000,bg='cadetblue4')
frame4.place(x=0,y=0)
listBox=Text(frame4,height = 38, width =
75,fg="white",bg="cadetblue4",font="Helvetica")
listBox.grid(row = 2,column= 0, columnspan = 2)
listBox.insert(END, " \t\t\t Display Total scores\t\n\n")
listBox.insert(END,"
----------------------------------------------------------------------------\n\n")
listBox.insert(END,"\tID \t\t Total score \t\t\n\n")
listBox.insert(END,"
---------------------------------------------------------------------------\n\n")
S=0
for i in x:

listBox.insert(END,"\t")
listBox.insert(END, i[0])
listBox.insert(END,"\t\t")
listBox.insert(END, i[1])
28
listBox.insert(END,"\t\t")
listBox.insert(END,"\n\n")
listBox.insert(END,"
----------------------------------------------------------------------------\n\n")

#function to display user incorrect answers to the database


def add_user_incorrect_answers():
sql = "select * from user_incorrect_answers"
mycursor.execute(sql)
add_user_incorrect_answers_window = tk.Tk()
add_user_incorrect_answers_window.title("Display User Incorrect
Answers")
add_user_incorrect_answers_window.geometry("600x600")

add_user_incorrect_answers_window.configure(background="cadetb
lue4")
x = mycursor.fetchall()

frame4=Frame(add_user_incorrect_answers_window,height=700,wid
th=1000,bg='cadetblue4')
frame4.place(x=0,y=0)
listBox=Text(frame4,height = 38, width =
75,fg="white",bg="cadetblue4",font="Helvetica")
listBox.grid(row = 2,column= 0, columnspan = 2)
listBox.insert(END, " \t\t\t Display incorrect Answers\t\n\n")
listBox.insert(END,"
----------------------------------------------------------------------------\n\n")
listBox.insert(END,"\tID \t\t No of incorrect Answers \t\t\n\n")
listBox.insert(END,"
---------------------------------------------------------------------------\n\n")
S=0
for i in x:

29
listBox.insert(END,"\t")
listBox.insert(END, i[0])
listBox.insert(END,"\t\t")
listBox.insert(END, i[1])
listBox.insert(END,"\t\t")
listBox.insert(END,"\n\n")
listBox.insert(END,"
----------------------------------------------------------------------------\n\n")

#function to display user correct answers to the database


def add_user_correct_answers():
sql = "select * from user_correct_answers"
mycursor.execute(sql)
add_user_correct_answers_window = tk.Tk()
add_user_correct_answers_window.title("Display User correct
Answers")
add_user_correct_answers_window.geometry("600x600")

add_user_correct_answers_window.configure(background="cadetblu
e4")
x = mycursor.fetchall()

frame4=Frame(add_user_correct_answers_window,height=700,width
=1000,bg='cadetblue4')
frame4.place(x=0,y=0)
listBox=Text(frame4,height = 38, width =
75,fg="white",bg="cadetblue4",font="Helvetica")
listBox.grid(row = 2,column= 0, columnspan = 2)
listBox.insert(END, " \t\t\t Display correct Answers\t\n\n")
listBox.insert(END,"
----------------------------------------------------------------------------\n\n")
listBox.insert(END,"\tID \t\t No of correct Answers \t\t\n\n")

30
listBox.insert(END,"
---------------------------------------------------------------------------\n\n")
S=0
for i in x:

listBox.insert(END,"\t")
listBox.insert(END, i[0])
listBox.insert(END,"\t\t")
listBox.insert(END, i[1])
listBox.insert(END,"\t\t")
listBox.insert(END,"\n\n")
listBox.insert(END,"
----------------------------------------------------------------------------\n\n")

#function to show the leaderboard of the game


def leaderboard():
leaderboard_window = tk.Tk()
leaderboard_window.title("Leaderboard")
leaderboard_window.geometry("600x600")
leaderboard_window.configure(background="light salmon")
mycursor.execute("SELECT * FROM user_total_score ORDER
BY user_total_score DESC")
x = mycursor.fetchall()

frame4=Frame(leaderboard_window,height=700,width=1000,bg='ca
detblue4')
frame4.place(x=0,y=0)
listBox=Text(frame4,height = 38, width =
75,fg="white",bg="cadetblue4",font="Helvetica")
listBox.grid(row = 2,column= 0, columnspan = 2)
listBox.insert(END, " \t\t\t LEADER BOARD\t\t\n\n")
listBox.insert(END,"
----------------------------------------------------------------------------\n\n")

31
listBox.insert(END,"\tID \t\t SCORE \t\n\n")
listBox.insert(END,"
---------------------------------------------------------------------------\n\n")
S=0
for i in x:

listBox.insert(END,"\t")
listBox.insert(END, i[0])
listBox.insert(END,"\t\t")
listBox.insert(END, i[1])
listBox.insert(END,"\t\t")
listBox.insert(END,"\n\n")
listBox.insert(END,"
----------------------------------------------------------------------------\n\n")

leaderboard_window.mainloop()

#function to delete questions from the database


def delete_questions():
def submit():
question = question_entry.get()
sql = "DELETE FROM questions WHERE id = %s"
val = (question,)
mycursor.execute(sql, val)
mydb.commit()
messagebox.showinfo("Success", "Question deleted
successfully")
show_questions.destroy()
delete_questions_window.destroy()

delete_questions_window = tk.Tk()
delete_questions_window.title("Delete Question")
32
delete_questions_window.geometry("400x400")
delete_questions_window.configure(background="light salmon")
question_label = tk.Label(delete_questions_window,
text="QUESTION ID",font=("Arial", 14),bg="grey",fg="white")
question_label.grid(row=0, column=0)
question_entry = tk.Entry(delete_questions_window,width=20,
font=("Arial", 14))
question_entry.grid(row=0, column=1)
submit_button = tk.Button(delete_questions_window,
text="Submit",bg="green", fg="white",
command=submit,font=("Arial", 14))
submit_button.grid(row=1, column=0)
show_questions()
delete_questions_window.mainloop()
adminMenu()

#function to show questions from the database


def show_questions():
show_questions_window = tk.Tk()
show_questions_window.title("Show Questions")
show_questions_window.geometry("1200x500")
show_questions_window.configure(background="light salmon")
mycursor.execute("SELECT * FROM questions")
myresult = mycursor.fetchall()
for x in myresult:
question_label = tk.Label(show_questions_window,
text=str(x[0]) + "."+ x[1],font=("Arial", 14))
question_label.pack()
show_questions_window.mainloop()

#function play the game

def gam(r):
33
def gsub(r,i):
mycursor.execute("select * from user where user='{}'
".format(i))
d=mycursor.fetchall()
if d !=[]:
messagebox.showinfo(" Let's Play "," user "+str(d[0][1]))
id=d[0][0]
game(r,id)
r.destroy()
gw = tk.Tk()
gw.title("Game")
gw.geometry("500x500")
gw.configure(background="honeydew3")
g_label = tk.Label(gw, text="USER ID " ,font=("Arial",
20),bg="grey",fg="white")
g_label.grid(row=0,column=0)
nE = Entry(gw, width=20,font=("Arial", 20))
nE.grid(row=0, column=200)
answer_label3 = tk.Button(gw, text="SUBMIT", font=("Arial",
20), command=lambda:gsub(gw,nE.get()),bg="green",fg="white")
answer_label3.place(x=0, y=100)

gw.mainloop()

ws=0
cs=0
score = 0
def game(r,id):
r.destroy()
global score

34
def submit(ans,crt,g,s,i):
global score
global ws,cs

s=s-1
if ans == crt:
messagebox.showinfo("Success", "Correct")
score+=1
cs+=1
if s==i:
messagebox.showinfo("Score", "Your score is
"+str(score),)
mycursor.execute("insert into user_correct_answers
values('{}',{})".format(id,cs))
mycursor.execute("insert into user_incorrect_answers
values('{}',{})".format(id,ws))
mycursor.execute("insert into user_total_score values('{}',
{})".format(id,score))
mydb.commit()
g.destroy()
ws=0
cs=0
score=0
MainMenu()

g.destroy()

else:
messagebox.showinfo("Error", "Incorrect")
ws+=1
if s==i:
messagebox.showinfo("Score", "Your score is
35
"+str(score),)
mycursor.execute("insert into user_correct_answers
values('{}',{})".format(id,cs))
mycursor.execute("insert into user_incorrect_answers
values('{}',{})".format(id,ws))
mycursor.execute("insert into user_total_score values('{}',
{})".format(id,score))
mydb.commit()
g.destroy()
ws=0
cs=0
score=0
MainMenu()

g.destroy()

mycursor.execute("SELECT * FROM questions")


questions=mycursor.fetchall()
mycursor.execute("SELECT * FROM answers")
answers=mycursor.fetchall()
mycursor.execute("SELECT * FROM correct_answers")
correct_answer=mycursor.fetchall()
cs=0
ws=0

for i in range (len(questions)):


s=len(questions)
game_window = tk.Tk()
game_window.title("Game")
game_window.geometry("1300x400")
game_window.configure(background="light blue")
correct= correct_answer[i][1]
36
question_label = tk.Label(game_window, text="Question
"+str(i+1), font=("Arial", 20),bg="grey",fg="white")
question_label.place(x=0, y=0)
question_entry = tk.Label(game_window, text=questions[i][1],
font=("Arial", 20),bg="grey",fg="white")
question_entry.place(x=0, y=50)
answer_label = tk.Button(game_window, text=answers[i][1],
font=("Arial", 20),command=lambda:submit(answers[i]
[1],correct,game_window,s,i),bg="grey",fg="white")
answer_label.place(x=0, y=100)
answer_label2 = tk.Button(game_window, text=answers[i][2],
font=("Arial", 20), command=lambda:submit(answers[i]
[2],correct,game_window,s,i),bg="grey",fg="white")
answer_label2.place(x=500, y=100)
answer_label3 = tk.Button(game_window, text=answers[i][3],
font=("Arial", 20), command=lambda:submit(answers[i]
[3],correct,game_window,s,i),bg="grey",fg="white")
answer_label3.place(x=0, y=200)
answer_label4 = tk.Button(game_window, text=answers[i][4],
font=("Arial", 20), command=lambda:submit(answers[i]
[4],correct,game_window,s,i),bg="grey",fg="white")
answer_label4.place(x=500, y=200)
game_window.mainloop()

sql = "INSERT INTO user_score (user_score) VALUES (%s)"


val = (score,)
mycursor.execute(sql, val)
mydb.commit()

#function to admin signup

def adminSignup():

def submit(na, Id):


37
mycursor.execute("insert into admin values (%s,%s)", (na, Id))
mydb.commit()
tk.messagebox.showinfo('Alert', 'Signup done successfully')
tk1.destroy()
adminLogin()

tk1 = tk.Tk()
tk1.resizable(False, False)
tk1.geometry("900x700")
tk1.title("ADMIN SIGNUP")
tk1.configure(background="pale goldenrod")

nameLabel = Label(tk1, text="Name:",font=("Arial",


20),bg="grey",fg="white")
nameLabel.grid(row=0, column=0, padx=10, pady=20)
nameEntry = Entry(tk1, width=37,font=("Arial", 20))
nameEntry.grid(row=0, column=1, padx=10, pady=20, ipady=2.2)

Id = Label(tk1, text='ID:',font=("Arial", 20),bg="grey",fg="white")


Id.grid(row=1, column=0)
idEntry = Entry(tk1, width=37,font=("Arial", 20))
idEntry.grid(row=1, column=1, padx=10, pady=20, ipady=2.21)

Button(tk1, text='submit',font=("Arial", 20),bg="green",


fg="white", command=lambda: submit(nameEntry.get(),
idEntry.get())).grid(row=2, column=1, padx=10,pady=10,
ipadx=100)

#function to admin login

def adminLogin():
def submit(name,Id):
mycursor.execute("select * from admin where name = %s and id
= %s", (name,Id))
38
admin = mycursor.fetchall()

if admin:
tk.messagebox.showinfo("Admin Login", "Login successful")
tk2.destroy()
adminMenu()
else:
tk.messagebox.showinfo("Admin Login", "Login failed")
tk2 = tk.Tk()
tk2.title("ADMIN LOGIN")
tk2.geometry("900x700")
name = tk.StringVar()
tk2.configure(background="light salmon")
Id = tk.StringVar()
name_label = tk.Label(tk2, text="Name", font=("bold",
20),bg="grey",fg="white")
name_label.place(x=20, y=20)
name_entry = tk.Entry(tk2, textvariable=name,width=20,
font=("Arial", 20))
name_entry.place(x=150, y=20)
Id_label = tk.Label(tk2, text="ID", font=("bold",
20),bg="grey",fg="white")
Id_label.place(x=20, y=70)
Id_entry = tk.Entry(tk2, textvariable=Id,width=20, font=("Arial",
20))
Id_entry.place(x=150, y=70)
submit_button = tk.Button(tk2, text="Submit",
width=20,font=("Arial", 20), bg="green", fg="white",
command=lambda:submit(name_entry.get(), Id_entry.get()))
submit_button.place(x=150, y=110)
tk.mainloop()

#function to admin menu

39
def adminMenu():
tk3= tk.Tk()
tk3.title("ADMIN MENU")
tk3.geometry("900x700")
tk3.configure(background="cadet blue")
add_button1 = tk.Button(tk3, text="ADD QUESTIONS",
width=35, bg="orange", fg="black",
command=lambda:add_questions(),font=("Arial", 20))
add_button1.place(x=150, y=20)
view_button2 = tk.Button(tk3, text="DELETE QUESTIONS",
width=35, bg="orange", fg="black",
command=lambda:delete_questions(),font=("Arial", 20))
view_button2.place(x=150, y=70)
view_button3 = tk.Button(tk3, text="ADD USER", width=35,
bg="orange", fg="black",
command=lambda:add_users(),font=("Arial", 20))
view_button3.place(x=150, y=120)
view_button4 = tk.Button(tk3, text="DISPLAY USER CORRECT
ANSWER", width=35, bg="orange", fg="black",
command=lambda:add_user_correct_answers(),font=("Arial", 20))
view_button4.place(x=150, y=170)
view_button5 = tk.Button(tk3, text="DISPLAY USER
INCORRECT ANSWER", width=35, bg="orange", fg="black",
command=lambda:add_user_incorrect_answers(),font=("Arial", 20))
view_button5.place(x=150, y=220)
view_button6 = tk.Button(tk3, text=" DISPLAYS TOTAL SCORE
OF USER", width=35, bg="orange", fg="black",
command=lambda:add_user_total_score(),font=("Arial", 20))
view_button6.place(x=150, y=270)

tk.mainloop()

#function to exit

def quit(r):
40
r.destroy()

#function to main page

def MainMenu():
tk4= tk.Tk()
tk4.title("QUIZ")
tk4.geometry("900x700")
tk4.configure(background="medium aquamarine")
label1 = Label(tk4, text="Welcome to Quiz", font=("Arial", 20),
fg="black",bg="light cyan")
label1.place(x=150, y=20)
add_button1 = tk.Button(tk4, text="ADMIN SIGNUP", width=30,
bg="grey", fg="white",
command=lambda:adminSignup(),font=("Arial", 20))
add_button1.place(x=150, y=80)
view_button2 = tk.Button(tk4, text="ADMIN LOGIN", width=30,
bg="grey", fg="white",
command=lambda:adminLogin(),font=("Arial", 20))
view_button2.place(x=150, y=130)
view_button3 = tk.Button(tk4, text="PLAY QUIZ", width=30,
bg="grey", fg="white", command=lambda:gam(tk4),font=("Arial",
20))
view_button3.place(x=150, y=180)
view_button4 = tk.Button(tk4, text="VIEW LEADERBOARD",
width=30, bg="grey", fg="white",
command=lambda:leaderboard(),font=("Arial", 20))
view_button4.place(x=150, y=230)
view_button5 = tk.Button(tk4, text="EXIT", width=30, bg="grey",
fg="white", command=lambda:quit(tk4),font=("Arial", 20))
view_button5.place(x=150, y=280)
tk.mainloop()

MainMenu()

41
OUTPUTS

#Main page

42
#Sign Up Page:

43
#Login Page:

44
#Admin Menu;

45
#Adding Question:

46
#Deleting Question:

47
#Adding User:

User-1:

48
User-2:

49
#Display Correct Answers of User:

50
#Display Incorrect Answers of User:

51
#Display Total Score of User:

52
#Play Quiz:

User 1:

53
54
55
56
User 2:

57
58
59
60
#View Leader Board :

61
USER MANUAL
About the application:

This application was created with the intention to make


learning easier through a graphical user interface in python
known as tkinter, it can also be considered as a mock tests .

Requirements for executing the project:

1. Windows 7/10 OS
2. Python 3.7.3 and above
3. MySQL 8.0

What should be done and what can be done using this application:

The Quiz Application has both user and admin terminal. To create the
database and tables, the admin must run the python function “def
add_defaultques()” for once.

In admin terminal :
The admin first sign up and login from the main page, so that the admin
will have access to the special functions like add questions, delete
questions, adding user, displaying user correct answers, displaying user
incorrect answers and displaying total score of the user.

In user terminal:
The user can play the quiz application if the user id exists and set a new
high score. The user can also see the high score set by all the other
users.

62
CONCLUSION

The Quiz application using Python, Tkinter and MySQL was a


successful project that allowed users to participate in a quiz with
multiple choice questions. The Tkinter library was used to create the
user interface, and MySQL was used to store and retrieve the questions
and answers from a database.

Overall, the application was able to achieve its goal of providing a


platform for users to participate in a quiz and test their knowledge. The
use of MySQL allowed for efficient storage and retrieval of the quiz
questions and answers, and the Tkinter library provided a user-friendly
interface for the users to interact with the application.

One of the key challenges faced during the development of the


application was ensuring that the questions and answers were properly
stored and retrieved from the MySQL database. However, with careful
planning and testing, this issue was effectively resolved.

In conclusion, the Quiz application using Python, Tkinter and MySQL


was a successful project that provided a platform for users to
participate in a quiz and test their knowledge. The use of Tkinter and
MySQL allowed for a user-friendly interface and efficient storage and
retrieval of the quiz questions and answers.

63
BIBLIOGRAPHY
TEXT BOOKS:
 COMPUTER SCIENCE with python XI-by SUMITA ARORA Published by
Dhanpat Rai and Sons.
 COMPUTER SCIENCE with python XII-by SUMITA ARORA Published by
Dhanpat Rai and Sons.

WEB SITES:
 https://www.tutorialspoint.com/python/python_gui_progr amming.html

 https://www.geeksforgeeks.org/python-gui-tkinter

 https://docs.python.org/3/library/tk.html

64

You might also like