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

Compprorep

Uploaded by

justgaming160
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Compprorep

Uploaded by

justgaming160
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 45

DELHI PUBLIC SCHOOL, WHITEFIELD

Academic Year 2023-2024

Project Report On
Quiz Game
FOR AISSCE 2024 EXAMINATION
[AS A PART OF THE COMPUTER SCIENCE COURSE (083)]

Name Class Section Roll No


Vaibhavi Mittal 12 A
Swara Wankhede 12 A

Page 1 of 46
CERTIFICATE

This is to certify that the Project/ Dissertation


entitled Quiz Game is a Bonafede work done by
Vaibhavi Mittal and Swara Wankhede of Class XII
Session 23-24 in partial fulfilment of CBSE's
AISSCE Examination 2024 and has been carried
out under my direct supervision and guidance.

………………………… ……………………………..
Signature of Principal Signature of Teacher

………………………… ……………………………..
Signature of Examiner Signature of Student

Page 2 of 46
ACKNOWLEDGEMENT

Apart from the efforts of the members of this team,


the success of any project depends largely on the
encouragement and guidelines of many others. We
take this opportunity to express our gratitude to the
people who have been instrumental in the
successful completion of this project.
We express a deep sense of gratitude to almighty
God for giving us strength for the successful
completion of the project.
We express our heartfelt gratitude to our parents
for their constant encouragement while carrying
out this project. We gratefully acknowledge the
contribution of the individuals who contributed to
bringing this project up to this level, who continues
to look after us despite our flaws.
Our sincere thanks to Ms. Pavithra NR, a guide and
a mentor, who critically reviewed our project and
helped in
solving every problem, that occurred during the
implementation of the project.

Page 3 of 46
Table of Contents

CERTIFICATE.............................................................2
ACKNOWLEDGEMENT..............................................3
INTRODUCTION.......................................................5
OBJECTIVE AND PROJECT DEFINITION....................6
HARDWARE AND SOFTWARE REQUIREMENTS......7
MODULES.................................................................8
Tkinter..........................................................8
Pillow...........................................................8
MYSQL Connector........................................9
Code and Output......................................................9
Database Description...................................9
Project code files.........................................10
Text files for question bank..........................10
MainGame.py................................................11
NewUser.py...................................................13
LoginGame.py................................................16
Quizgame.py..................................................19
ShowScore.py.................................................27
deleteUser.py................................................30
BIBLOGRAPHY...........................................................33

Page 4 of 46
INTRODUCTION
Quiz
Game:
Games are essential for development of the
students. It nurtures the competitive sprit in
students. This quiz game will enhance the
knowledge of the students on different subject.

Page 5 of 46
OBJECTIVE AND PROJECT
DEFINITION

In this project we have used many


programming features that we learned
throughout the year.
We have used File management as Question
bank for all the subjects.
We are using Database to store the user
Information to allow user to login and to save
their scores.
We have used TKinter to make the GUI of the
application.
We have used Pillow to show the image on the
screen.
We have used list extensively to load the
question bank and show random questions.

Page 6 of 46
HARDWARE AND SOFTWARE
REQUIREMENTS
1. PC with Intel core i5 with 64 GB RAM and 64
bit OS
2. MS Windows 11 OS
3. Python 5.5
4. IDLE (Python 5.5)
5. Python Libraries
a. TKinter
b. Pillow
c. MySQL Connector
6. MySQL DB

Page 7 of 46
MODULES
Tkinter
Tkinter is a useful tool for creating a wide
variety of graphical user interfaces, including
windows, dialog boxes, and custom widgets. It
is particularly well-suited for building desktop
applications and adding a GUI to command-line
programs. It is indeed one of the fastest and
easiest ways to build GUI applications.
Moreover, Tkinter is cross-platform, hence the
same code works on macOS, Windows, and
Linux.
To install Tkinter: pip install Tk

Pillow
The Pillow library in Python contains all the
basic image processing functionality. We can
rotate, resize and transform an image. In this
code, the Pillow module has been used in
defining the backgrounds that appear as the
output.
To install Pillow: pip install pillow

Page 8 of 46
MYSQL Connector
MySQL Connector/Python enables Python
programs to access MySQL databases, using an
API that is compliant with the python.

Code and Output


Database Description:

Tables:

Page 9 of 46
Project code files:
S.no. File Name Description
1 MainGame.py Main window of the project gives user all the
options provided by the
application
2 NewUser.py This window of the application allow user to add new
user
3 LoginGame.py This window allows user to login to play the quiz
4 Quizgame.py This is the window to show the questions and
receive the answers
5 ShowScore.py After the quiz it shows the score
6 deleteUser.py To delete a user from DB only Admin can delete the
user

Text files for question bank


1. GK_ques.txt
2. GK_ans.txt
3. Comp_ques.txt
4. Comp_ans.txt
5. Math_ques.txt
6. Math_ans.txt
7. Sci_ques.txt
8. Sci_ans.txt
Image file for main window
1. myimg.jpeg
Page 10 of 33
MainGame.py:
from random import randint
from tkinter import messagebox
from tkinter import *
import tkinter as tk
import os
from flIL import ImageTk, Image
from LoginGame import *
from ewUser import *
from deleteUser import *

Main_window = Tk()
Main_window.title("Game")
shight =
Main_window.winfo_screenheight()
swidth =
Main_window.winfo_screenwidth()
Main_window.geometry("%dx%d" %(swidth,shight))
Adding background
bkImg =
Image.open("myimg.jpeg") img =
ImageTk.flhotoImage(bkImg)

Canvas1=Canvas(Main_window)
Canvas1.create_image(300,300,image=img)
Canvas1.config (bg="Green",width=swidth,height=shight)
Canvas1.pack(expand=True,fill=BOTH)

headingFrame1 = Frame(Main_window,bg=" FFBB00",bd=5)


headingFrame1.place(relx=0.2,rely=0.1,relwidth=0.6,relheight=0.16)
headingLabel = Label(headingFrame1, text=" Welcome to \nWorld of Quiz",
bg='black', fg='white',font=('Century 15 bold'))
headingLabel.place(relx=0,rely=0, relwidth=1, relheight=1)

btn1 = Button(Main_window,text="login to fllay",bg='black', fg='white',


command=login2game,font=('Century 15'))
btn1.place(relx=0.28,rely=0.4, relwidth=0.45,relheight=0.1)

btn2 = Button(Main_window,text=" ew User",bg='black', fg='white',


command=newu,font=('Century 15'))
btn2.place(relx=0.28,rely=0.5, relwidth=0.45,relheight=0.1)

btn3 = Button(Main_window,text="Delete User",bg='black', fg='white',


command=adminl,font=('Century 15'))
btn3.place(relx=0.28,rely=0.6, relwidth=0.45,relheight=0.1)

btn4 = Button(Main_window,text="Quit",bg='black', fg='white',


command=Main_window.destroy,font=('Century 15'))
btn4.place(relx=0.28,rely=0.7, relwidth=0.45,relheight=0.1)
Main_window.mainloop()

Page 11 of 46
Output:

Page 12 of 46
NewUser.py:
from random import
randint from tkinter
import messagebox from
tkinter import *
import tkinter
as tk import os
from flIL import ImageTk,
Image import mysql.connector
nu_pwd=
one nu_U
ame= one
nu_UID= one
def newu():
global Main_window, Canvas1, nu_U ame,
nu_pwd,nu_UID Main_window = Tk()
Main_window.title("QuizGame ew
User")
Main_window.minsize(width=400,heig
ht=400)
Main_window.geometry("600x500")

Canvas1 =
Canvas(Main_window)
Canvas1.config(bg="
ff6e40")
Canvas1.config(bg=" ffce30")
Canvas1.pack(expand=True,fill=BOTH)

headingFrame1 = Frame(Main_window,bg=" FFBB00",bd=5)


headingFrame1.place(relx=0.25,rely=0.1,relwidth=0.5,relheight=0
.13)

headingLabel = Label(headingFrame1, text="Game ew


User", bg='black', fg='white', font=('Century 15'))
headingLabel.place(relx=0,rely=0, relwidth=1, relheight=1)

labelFrame = Frame(Main_window,bg='black')
labelFrame.place(relx=0.1,rely=0.4,relwidth=0.8,relheight=0.4)

lb1 = Label(labelFrame,text="UserID : ", bg='black',


fg='white') lb1.place(relx=0.05,rely=0.2, relheight=0.08)

nu_UID = Entry(labelFrame)
nu_UID.place(relx=0.3,rely=0.2, relwidth=0.62, relheight=0.08)
Page 13 of 46
lb2 = Label(labelFrame,text="User ame : ", bg='black',
fg='white') lb2.place(relx=0.05,rely=0.35, relheight=0.08)

nu_U ame = Entry(labelFrame)


nu_U ame.place(relx=0.3,rely=0.35, relwidth=0.62,
relheight=0.08)

Page 14 of 46
lb3 = Label(labelFrame,text="flassword : ", bg='black',
fg='white') lb3.place(relx=0.05,rely=0.5, relheight=0.08)

nu_pwd = Entry(labelFrame)
nu_pwd.place(relx=0.3,rely=0.5, relwidth=0.62, relheight=0.08)

Submit Button
SubmitBtn = Button(Main_window,text="Add User",bg=' d1ccc0',
fg='black',command=adduser)
SubmitBtn.place(relx=0.28,rely=0.9,
relwidth=0.18,relheight=0.08) quitBtn =
Button(Main_window,text="Quit",bg=' f7f1e3', fg='black',
command=Main_window.destroy)
quitBtn.place(relx=0.53,rely=0.9,
relwidth=0.18,relheight=0.08)

Main_window.mainloo
p() def adduser():
global nu_U ame,
nu_pwd,nu_UID,Main_window need to
connect to db

con=mysql.connector.connect(host="localhost",user="root",password
="Tiaa123$"
,database="quizgam
e") cur =
con.cursor()
suname = nu_U
ame.get() spwd =
nu_pwd.get() suid =
nu_UID.get()
values="('"+suid+"' ,'"+suname+"' ,'"
+spwd+"')" print(values)
userTable = "gameplayer"
extractInfo="select * from {} where
id='{}'".format(userTable,suid) print (extractInfo)
try:
cur.execute(extractInfo
) data =cur.fetchall()
Count=cur.rowcount
print (data)
print("rowCount=",Co
unt) if Count>0:
messagebox.showinfo("Error","User already exist!")
Main_window.destroy()
Page 15 of 46
else:
extractInfo1="insert into {} value
{}".format(userTable,values)
cur.execute(extractInfo1)
con.commit()
messagebox.showinfo("Success", "User Added
successfully") Main_window.destroy()

Page 16 of 46
except:
messagebox.showinfo("Error", "Can't get the gameplayer
data") Main_window.destroy()

Output:

Page 17 of 46
LoginGame.py:
from random import
randint from tkinter
import messagebox from
tkinter import *
import tkinter
as tk import os
from flIL import ImageTk,
Image import mysql.connector
from Quizgame import *

txpwd=
one U
ame= one

def login2game():
global Main_window,
Canvas1,txpwd,U ame Main_window
= Tk()
Main_window.title("QuizGame
login")
Main_window.minsize(width=400,heig
ht=400)
Main_window.geometry("600x500")
Add your own database name and password here to reflect in
the code

con=mysql.connector.connect(host="localhost",user="root",passwor
d="Abc",dat abase="db")
cur = con.cursor()
Enter Table ames
here

Canvas1 =
Canvas(Main_window)
Canvas1.config(bg="
ff6e40")
Canvas1.config(bg=" 800080")
Canvas1.pack(expand=True,fill=BOTH)

headingFrame1 = Frame(Main_window,bg=" FFBB00",bd=5)


headingFrame1.place(relx=0.25,rely=0.1,relwidth=0.5,relheight=0
.13)

headingLabel = Label(headingFrame1, text="Game Login",


Page 18 of 46
bg='black', fg='white', font=('Century 15'))
headingLabel.place(relx=0,rely=0, relwidth=1, relheight=1)

labelFrame = Frame(Main_window,bg='black')
labelFrame.place(relx=0.1,rely=0.4,relwidth=0.8,relheight=0.4)

lb1 = Label(labelFrame,text="Username : ", bg='black',


fg='white') lb1.place(relx=0.05,rely=0.2, relheight=0.08)

U ame = Entry(labelFrame)

Page 19 of 46
U ame.place(relx=0.3,rely=0.2, relwidth=0.62, relheight=0.08)

lb2 = Label(labelFrame,text="flassword : ", bg='black',


fg='white') lb2.place(relx=0.05,rely=0.35, relheight=0.08)

txpwd = Entry(labelFrame)
txpwd.place(relx=0.3,rely=0.35, relwidth=0.62, relheight=0.08)

Submit Button
SubmitBtn = Button(Main_window,text="SUBMIT",bg=' d1ccc0',
fg='black',command=glogin)
SubmitBtn.place(relx=0.28,rely=0.9,
relwidth=0.18,relheight=0.08) quitBtn =
Button(Main_window,text="Quit",bg=' f7f1e3', fg='black',
command=Main_window.destroy)
quitBtn.place(relx=0.53,rely=0.9,
relwidth=0.18,relheight=0.08)

Main_window.mainloop()

def glogin():
global U
ame,txpwd,Canvas1,userTable,Main_window

con,cur, suname = U ame.get()


spwd = txpwd.get()
print ("workin progress for login uid=" ,suname
,"pwd=",spwd) need to check DB if the username and
flWD is correct.

con=mysql.connector.connect(host="localhost",user="root",password
="Tiaa123$"
,database="quizgam
e") cur =
con.cursor()
userTable = "gameplayer"
extractInfo="select * from {} where
id='{}'".format(userTable,suname) try:
cur.execute(extractI
nfo) data
=cur.fetchall() print
(data)
if data[0]
[0]==suname: if
data[0]
[2]==spwd:
Page 110 of
46
Main_window.destroy()
play(suname)

else:
messagebox.showinfo("Error", "Username or password
valid not
")
Main_window.destroy()
else:
messagebox.showinfo("Error", "Username or password
not valid") Main_window.destroy()

Page 111 of
46
except:
messagebox.showinfo("Error", "Can't get the gameplayer
data") Main_window.destroy()

Output

Page 112 of
46
Quizgame.py:
from random import
randint from tkinter
import messagebox from
tkinter import *
import tkinter
as tk import os
from flIL import ImageTk,
Image import mysql.connector
from ShowScore
import *
questionsGK=[]
AnswersGK=[]
questionsMath=[]
AnswersMath=[]
questionsSic=[]
AnswersSic=[]
questionsComp=[]
AnswersComp=[]

qList=[]
ansList=[]
qvar1= one
question="
" first=0
count=0
score=0
Skipcount=
0 ans=""
my_label=
one
qlableText=
one qlb1= one
headingFrame1=
one
headingLabel=
one
qlabelFrame=
one uname=""
subject=""
creating the tkinter window

def importans(file,alist):
file_name =
Page 113 of
46
os.path.join(os.getcwd(), file) print
(file_name)
file_ans = open(file_name,
'r') count = 0
linetype
=0 line
="a"

Page 114 of
46
while True:
count += 1
Get next line from
file line =
file1.readline()
if line is empty
end of file is
reached line =
file_ans.readline() if
not line:
break
print(line);
alist=line.split("
,") print(alist)
question_list.append(li
ne) file_ans.close()
print(count)
return alist

def
importquiz(file,question_l
ist): """
read the quiz file and import it
in list. """
file = os.getcwd()+file
file = os.path.join(os.getcwd(),
file) file_name =
os.path.join(os.getcwd(), file) print
(file_name)
file1 = open(file_name,
'r') count = 0
linetype
=0 line
="a"
while True:
count += 1
Get next line from
file line =
file1.readline()
if line is empty
end of file is
reached line =
file1.readline() if
not line:
break
question_list.append(li
Page 20 of 33
ne)
print("Line{}: {}".format(count,
line.strip())) file1.close()
print(count)
return question_list

def showQuestion():
global ans, qList,
ansList,count,qlableText,ansList,qlb1,uname

Page 20 of 33
print ("in
showQuestion") if
(count==5):
show result
text1="you score "+str(score)+ " outof
5" messagebox.showinfo( "Result",
text1) addscoretoDB()
exit(0)
else:
print("inside else
count=",count)
qno=randint(0,9-count)
print("inside else qno=",qno)
count=count+1
q=qList.pop(qno
)
tokens=q.split("
|")

qu=tokens[0]+"\n"+tokens[1]+"\n"+tokens[2]+"\n"+tokens[3]+"\
n"+tokens[4] qlableText.set(qu)
print(ansList)
ans=ansList.pop(
qno)

def addscoretoDB():
global uname,subject,score
print ("user=",uname,"sub=" ,subject,"score=",score)

con=mysql.connector.connect(host="localhost",user="root",password
="Tiaa123$"
,database="quizgam
e") cur =
con.cursor()
userTable =
"scores"
values="('"+uname+"',"+score+",'"+subje
ct+"')" extractInfo1="insert into {} value
('{}',{},'{}')".format(userTable,uname,score,subject)
cur.execute(extractInfo1)
con.commit()
ShowScoreScreen(uname,sub
ject)

def verifyAns():
Page 21 of 46
global ans,score,qvar1
messagebox.showinfo("verifyAns",str(qvar1.get()))
if
(ans==str(qvar1.get(
))): score=score+1
print("inside verifyAns
ans=",ans,"Uans=",str(qvar1.get()),"score=",score)

def submitCallBack():

Page 22 of 46
global
subject,first,qvar1,qList,questionsGK,questionsMath,questionsSic,
questionsCo
mp,AnswersGK,AnswersMath,AnswersSic,AnswersComp,ansList
print("qvar1.get()=",qvar1.get())
if(first==0):
messagebox.showinfo( "submit",
str(qvar1.get())) first=1
if(str(qvar1.get())=="
1"): print("GK")
subject="GK"
importquiz('Questions\GK_ques.txt',questionsGK)
AnswersGK=importans('Questions\GK_ans.txt',AnswersGK)
print(AnswersGK)
qList=questionsGK
ansList=AnswersGK
elif(str(qvar1.get())=
="2"):
print("math")
subject="Math"
importquiz('Questions\Math_ques.txt',questionsMath)
AnswersMath=importans('Questions\
Math_ans.txt',AnswersMath) qList=questionsMath
ansList=AnswersMa
th
elif(str(qvar1.get())=
="3"):
print("science")
subject="Science"
importquiz('Questions\Sci_ques.txt',questionsSic)
AnswersSic=importans('Questions\
Sci_ans.txt',AnswersSic) qList=questionsSic
ansList=AnswersSi
c
elif(str(qvar1.get())=
="4"):
print("Comp
science")
subject="Comput
er"
importquiz('Questions\Comp_ques.txt',questionsComp)
AnswersComp=importans('Questions\
Comp_ans.txt',AnswersComp) qList=questionsComp
ansList=AnswersComp
showQuestion()
else:
Page 23 of 46
addscoretoDB()
qMain_window.destroy()

def nextCallBack():
global first, qList, ansList,var,qlableText

verifyAns()
showQuestion()

Page 24 of 46
def skipCallBack():
global
Skipcount
if(Skipcount==1)
:
messagebox.showinfo ("Skip","You already skiped 1
question, \ncannot skip this one")
else:
Skipcount=Skipcount+1
showQuestion()

def sel():
messagebox.showinfo("sel",va
r.get()) a=2

def play(user):
global qMain_window, qvar1,qlableText,qlb1,qlabelFrame,uname
qMain_window = Tk()
qMain_window.title("Quiz Game")
qMain_window.minsize(width=400,heigh
t=400)
qMain_window.geometry("600x500")
uname=user
qCanvas1 = Canvas(qMain_window)
qCanvas1.config(bg=" B22222")
qCanvas1.pack(expand=True,fill=BOT
H)

headingFrame1 = Frame(qMain_window,bg=" FFBB00",bd=5)


headingFrame1.place(relx=0.25,rely=0.1,relwidth=0.5,relheight=0.13
) wel="Welcome "+uname
headingLabel = Label(headingFrame1, text=wel, bg='black',
fg='white', font=('Century 15'))
headingLabel.place(relx=0,rely=0, relwidth=1, relheight=1)

qlabelFrame = Frame(qMain_window,bg='black')
qlabelFrame.place(relx=0.1,rely=0.3,relwidth=0.8,relheight=0.6)

qlableText=tk.StringVar()
qlb1 = Label(qlabelFrame, textvariable=qlableText,
bg='black', fg='white',font=('Century
12'),justify=LEFT,wraplength=450)
qlableText.set("Select The Quiz subject from below options\n\
nA) GK\nB) Math\nC) Science\nD) flython ")
Page 25 of 46
qlb1.place(relx=0.05,rely=0.02, relwidth=0.9,relheight=0.5)

qvar1 = IntVar()
R1 = Radiobutton(qlabelFrame, text="A", variable=qvar1,
value=1,
fg='black',bg='white',command=sel).place(relx=.1,rely=.55)

Page 26 of 46
R2 = Radiobutton(qlabelFrame, text="B", variable=qvar1,
value=2,
fg='black',bg='white',command=sel).place(relx=.5,rely=.55)
R3 = Radiobutton(qlabelFrame, text="C", variable=qvar1,
value=3,
fg='black',bg='white',command=sel).place(relx=.1,rely=.7)
R4 = Radiobutton(qlabelFrame, text="D", variable=qvar1,
value=4,
fg='black',bg='white',command=sel).place(relx=.5,rely=.7)

Submit Button
nxtBtn = Button(qMain_window,text=" ext",bg=' d1ccc0',
fg='black',command=nextCallBack)
nxtBtn.place(relx=0.2,rely=0.9,
relwidth=0.18,relheight=0.08) SubmitBtn =
Button(qMain_window,text="SUBMIT",bg=' d1ccc0',
fg='black',command=submitCallBack)
SubmitBtn.place(relx=0.4,rely=0.9,
relwidth=0.18,relheight=0.08)
quitBtn = Button(qMain_window,text="Quit",bg=' f7f1e3',
fg='black', command=qMain_window.destroy)
quitBtn.place(relx=0.6,rely=0.9,
relwidth=0.18,relheight=0.08)

qMain_window.mainloop()

Page 27 of 46
Output:

Page 28 of 46
Page 29 of 46
ShowScore.py:
from random import
randint from tkinter
import messagebox from
tkinter import *
import tkinter
as tk import os
from flIL import ImageTk,
Image import mysql.connector
from Quizgame import *
uname=''
subject=''
def ShowScoreScreen(user,sub):
global Main_window,
Canvas1,uname,subject
Main_window = Tk()
Main_window.title("QuizGame
Score")
Main_window.minsize(width=400,heig
ht=400)
Main_window.geometry("600x500")
uname=user
subject=sub
Canvas1 =
Canvas(Main_window)
Canvas1.config(bg="
ff6e40")
Canvas1.config(bg=" FFFACD")
Canvas1.pack(expand=True,fill=BOTH)

headingFrame1 = Frame(Main_window,bg=" FFBB00",bd=5)


headingFrame1.place(relx=0.25,rely=0.1,relwidth=0.5,relheight=0
.13)

headingLabel = Label(headingFrame1,
text="Score", bg='black', fg='white', font=('Century
15'))
headingLabel.place(relx=0,rely=0, relwidth=1, relheight=1)

labelFrame=Frame( Main_window,bg='black')
labelFrame.place(relx=0.1,rely=0.3,relwidth=0.8,
relheight=0.5)

Label(labelFrame,text="%-20s%-10s%- 20s"%
('ID','Score','Subject'),bg='black',fg='white').place(relx=0.07,
Page 210 of
46
rely=0. 1)
Label(labelFrame,text="
-",bg='black',fg='white').place(relx=0.07,rely=0.2)

con=mysql.connector.connect(host="localhost",user="root",password
="Tiaa123$"
,database="quizgam
e") cur =
con.cursor()
userTable =
"scores"

Page 211 of
46
extractInfo="select * from {} where ID='{}' and
subject='{}'".format(userTable,uname,subject)
print
(extractInfo)
y=0.3
try:
cur.execute(extractInfo
) data =cur.fetchall()
messagebox
("Score",data)
print(data)

for i in data:
Label(labelFrame,text="%-20s%-10s%- 20s"%
(i[0],i[1],i[2]),bg='black',fg='white').place(relx=0.07,rely=y)
y=y+0.1
except:
messagebox.showinfo("Error", "Can't get the
gameplayer data") exitBT =
Button(Main_window,text="Exit",bg=' f7f1e3', fg='black',
command=Main_window.destroy)
exitBT .place(relx=0.4,rely=0.9,relwidth=0.18,relheight=0.18)
Main_window.mainloop()

Page 212 of
46
Output:

Page 213 of
46
deleteUser.py:
from random import
randint from tkinter
import messagebox from
tkinter import *
import tkinter
as tk import os
from flIL import ImageTk,
Image import mysql.connector
from Quizgame import *

tpwd= one
dUser =

one

def adminl():
global Main_window,
Canvas1,tpwd,dUser Main_window
= Tk() Main_window.title("Delete
User")
Main_window.minsize(width=400,heig
ht=400)
Main_window.geometry("600x500")

Canvas1 =
Canvas(Main_window)
Canvas1.config(bg="
ff6e40")
Canvas1.config(bg=" 288BA8")
Canvas1.pack(expand=True,fill=BOTH)

headingFrame1 = Frame(Main_window,bg=" FFBB00",bd=5)


headingFrame1.place(relx=0.25,rely=0.1,relwidth=0.5,relheight=0
.13)

headingLabel = Label(headingFrame1, text="Delete User",


bg='black', fg='white', font=('Century 15'))
headingLabel.place(relx=0,rely=0, relwidth=1, relheight=1)

labelFrame = Frame(Main_window,bg='black')
labelFrame.place(relx=0.1,rely=0.4,relwidth=0.8,relheight=0.4)

lb1 = Label(labelFrame,text="Username : ", bg='black',


fg='white') lb1.place(relx=0.05,rely=0.2, relheight=0.08)
Page 30 of 33
lb2 = Label(labelFrame,text="admin", bg='black',
fg='white') lb2.place(relx=0.3,rely=0.2, relwidth=0.62,
relheight=0.08)

lb1 = Label(labelFrame,text="Admin flassword : ", bg='black',


fg='white') lb1.place(relx=0.05,rely=0.2, relheight=0.08)
tpwd = Entry(labelFrame)
tpwd.place(relx=0.3,rely=0.2, relwidth=0.62, relheight=0.08)

Page 30 of 33
lb2 = Label(labelFrame,text="Delete User : ", bg='black',
fg='white') lb2.place(relx=0.05,rely=0.35, relheight=0.08)

dUser = Entry(labelFrame)
dUser.place(relx=0.3,rely=0.35, relwidth=0.62, relheight=0.08)

Submit Button
SubmitBtn = Button(Main_window,text="SUBMIT",bg=' d1ccc0',
fg='black',command=alogin)
SubmitBtn.place(relx=0.28,rely=0.9,
relwidth=0.18,relheight=0.08) quitBtn =
Button(Main_window,text="Quit",bg=' f7f1e3', fg='black',
command=Main_window.destroy)
quitBtn.place(relx=0.53,rely=0.9,
relwidth=0.18,relheight=0.08)

Main_window.mainloop()

def deleteUser(delU):

con=mysql.connector.connect(host="localhost",user="root",password
="Tiaa123$"
,database="quizgam
e") cur =
con.cursor()
userTable =
"scores"
extractInfo="delete from {} where
id='{}'".format(userTable,delU) extractInfo1="delete from
{} where id='{}'".format ("gameplayer",delU)
print(extractInf
o) try:
cur.execute(extractInf
o)
cur.execute(extractInfo
1) con.commit();
messagebox.showinfo("Success", "User Delete
Successfully") except:
messagebox.showinfo("Error", "Can't get the data from
DB") Main_window.destroy()

def alogin():
global U
Page 31 of 46
ame,tpwd,Canvas1,userTable,Main_window,dUser

con,cur, suname = "admin"


spwd =
tpwd.get() delU
= dUser.get() if
(delU=='admin')
:
messagebox.showinfo("Error", "admin Usercannot be
deleted") Main_window.destroy()
else:

Page 32 of 46
print ("workin progress for login
uid=" ,suname ,"pwd=",spwd) need to check DB if the
username and flWD is correct.

con=mysql.connector.connect(host="localhost",user="root",passwor
d="Tiaa123$"
,database="quizgame")
cur = con.cursor()
userTable =
"gameplayer"
extractInfo="select * from {} where
id='{}'".format(userTable,suname)
print(extractInfo
) try:
cur.execute(extractI
nfo) data
=cur.fetchall()
print (data)
if data[0]
[0]==suname: if
data[0]
[2]==spwd:
deleteUser(delU)
Main_window.destroy()
play()
else:
messagebox.showinfo("Error", "You should be
admin to
delete user")
Main_window.destroy()
else:
messagebox.showinfo("Error", "You should be admin

Page 33 of 46
Output:

BIBLOGRAPHY
1. https://www.mysql.com
2. https://pypi.org/project/Pillow/
3. https://docs.python.org/3/library/tkinter.html
4. https://www.w3schools.com/python/
5. Computer Science with Python (Textbook for Class XII) –
Sumita Arora
Page 34 of 46

You might also like