Quiz Application In Python With Source Code
The Quiz Application In Python is written in python programming language, This Simple Quiz On Python Programming is a simple project for testing one’s knowledge power in the given topic examination. The project Quiz In Python contains only the user side. The user must log in or sign up first to start the Quiz On Python. Also, there is a time duration set for solving the questions. The user should solve the questions before time is up.
A Quiz Project In Python just contains the user section. The user can log in to give the exam. After giving the exam, the user can see their score and evaluate themselves. The design of this project Quiz Program In Python Using Tkinter is pretty simple so that the user won’t find any difficulties while working on it.
Watch the video here to see the full running of Quiz Application In python with source code.
Anyway if you want level up your knowledge in programming especially games in python, try this new article I’ve made for you Code For Game in Python: Python Game Projects With Source Code
This Quiz On Python Code also includes a downloadable Python Quiz Game Source Code, just find the downloadable source code below and click to start downloading.
To start creating a Quiz Application In Python, make sure that you have PyCharm IDE installed in your computer.
Steps on How To Create Quiz In Python
Quiz Application In Python With Source Code
- Step 1: Create a project name.
First open Pycharm IDE and then create a “project name” after creating a project name click the “create” button.
- Step 2: Create a Python file.
Second after creating a project name, “right click” your project name and then click “new” after that click the “python file“.
- Step 3: Name your python file.
Third after creating a python file, Name your python file after that click “enter“.
- Step 4: The actual code.
You are free to copy the code given below and download the full source code below.
The Code Given Below Is For Importing Modules
1 2 3 4 5 |
import tkinter as tk from tkinter import * import random import sqlite3 import time |
The code given which is importing all modules.
The Code Given Below Is For The Module Log In Page
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
def loginPage(logdata): sup.destroy() global login login = Tk() user_name = StringVar() password = StringVar() login_canvas = Canvas(login,width=720,height=440,bg="blue") login_canvas.pack() login_frame = Frame(login_canvas,bg="white") login_frame.place(relwidth=0.8,relheight=0.8,relx=0.1,rely=0.1) heading = Label(login_frame,text="Quiz App Login",fg="black",bg="white") heading.config(font=('calibri 40')) heading.place(relx=0.2,rely=0.1) #USER NAME ulabel = Label(login_frame,text="Username",fg='black',bg='white') ulabel.place(relx=0.21,rely=0.4) uname = Entry(login_frame,bg='#d3d3d3',fg='black',textvariable = user_name) uname.config(width=42) uname.place(relx=0.31,rely=0.4) #PASSWORD plabel = Label(login_frame,text="Password",fg='black',bg='white') plabel.place(relx=0.215,rely=0.5) pas = Entry(login_frame,bg='#d3d3d3',fg='black',show="*",textvariable = password) pas.config(width=42) pas.place(relx=0.31,rely=0.5) def check(): for a,b,c,d in logdata: if b == uname.get() and c == pas.get(): menu() break else: error = Label(login_frame,text="Wrong Username or Password!",fg='black',bg='white') error.place(relx=0.37,rely=0.7) #LOGIN BUTTON log = Button(login_frame,text='Login',padx=5,pady=5,width=5,command=check) log.configure(width = 15,height=1, activebackground = "#33B5E5", relief = FLAT) log.place(relx=0.4,rely=0.6) login.mainloop() |
In this module which is the user log in page.

The Code Given Below Is For The Sign Up Page Module
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
def signUpPage(): root.destroy() global sup sup = Tk() fname = StringVar() uname = StringVar() passW = StringVar() country = StringVar() sup_canvas = Canvas(sup,width=720,height=440,bg="blue") sup_canvas.pack() sup_frame = Frame(sup_canvas,bg="white") sup_frame.place(relwidth=0.8,relheight=0.8,relx=0.1,rely=0.1) heading = Label(sup_frame,text="Quiz App SignUp",fg="black",bg="white") heading.config(font=('calibri 40')) heading.place(relx=0.2,rely=0.1) #full name flabel = Label(sup_frame,text="Full Name",fg='black',bg='white') flabel.place(relx=0.21,rely=0.4) fname = Entry(sup_frame,bg='#d3d3d3',fg='black',textvariable = fname) fname.config(width=42) fname.place(relx=0.31,rely=0.4) #username ulabel = Label(sup_frame,text="Username",fg='black',bg='white') ulabel.place(relx=0.21,rely=0.5) user = Entry(sup_frame,bg='#d3d3d3',fg='black',textvariable = uname) user.config(width=42) user.place(relx=0.31,rely=0.5) #password plabel = Label(sup_frame,text="Password",fg='black',bg='white') plabel.place(relx=0.215,rely=0.6) pas = Entry(sup_frame,bg='#d3d3d3',fg='black',show="*",textvariable = passW) pas.config(width=42) pas.place(relx=0.31,rely=0.6) #country clabel = Label(sup_frame,text="Country",fg='black',bg='white') clabel.place(relx=0.215,rely=0.7) c = Entry(sup_frame,bg='#d3d3d3',fg='black',textvariable = country) c.config(width=42) c.place(relx=0.31,rely=0.7) def addUserToDataBase(): fullname = fname.get() username = user.get() password = pas.get() country = c.get() conn = sqlite3.connect('quiz.db') create = conn.cursor() create.execute('CREATE TABLE IF NOT EXISTS userSignUp(FULLNAME text, USERNAME text,PASSWORD text,COUNTRY text)') create.execute("INSERT INTO userSignUp VALUES (?,?,?,?)",(fullname,username,password,country)) conn.commit() create.execute('SELECT * FROM userSignUp') z=create.fetchall() print(z) # L2.config(text="Username is "+z[0][0]+"\nPassword is "+z[-1][1]) conn.close() loginPage(z) def gotoLogin(): conn = sqlite3.connect('quiz.db') create = conn.cursor() conn.commit() create.execute('SELECT * FROM userSignUp') z=create.fetchall() loginPage(z) #signup BUTTON sp = Button(sup_frame,text='SignUp',padx=5,pady=5,width=5,command = addUserToDataBase,bg='green') sp.configure(width = 15,height=1, activebackground = "#33B5E5", relief = FLAT) sp.place(relx=0.4,rely=0.8) log = Button(sup_frame,text='Already have a Account?',padx=5,pady=5,width=5,command = gotoLogin,bg="white",fg='blue') log.configure(width = 16,height=1, activebackground = "#33B5E5", relief = FLAT) log.place(relx=0.4,rely=0.9) sup.mainloop() |
In this module which is the user registration or the sign up page.

The Code Given Below Is For The Module Menu
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 |
def menu(): login.destroy() global menu menu = Tk() menu_canvas = Canvas(menu,width=720,height=440,bg="blue") menu_canvas.pack() menu_frame = Frame(menu_canvas,bg="white") menu_frame.place(relwidth=0.8,relheight=0.8,relx=0.1,rely=0.1) wel = Label(menu_canvas,text=' W E L C O M E T O Q U I Z S T A T I O N ',fg="white",bg="#101357") wel.config(font=('Broadway 22')) wel.place(relx=0.1,rely=0.02) level = Label(menu_frame,text='Select your Difficulty Level !!',bg="white",font="calibri 18") level.place(relx=0.25,rely=0.3) var = IntVar() easyR = Radiobutton(menu_frame,text='Easy',bg="white",font="calibri 16",value=1,variable = var) easyR.place(relx=0.25,rely=0.4) mediumR = Radiobutton(menu_frame,text='Medium',bg="white",font="calibri 16",value=2,variable = var) mediumR.place(relx=0.25,rely=0.5) hardR = Radiobutton(menu_frame,text='Hard',bg="white",font="calibri 16",value=3,variable = var) hardR.place(relx=0.25,rely=0.6) def navigate(): x = var.get() print(x) if x == 1: menu.destroy() easy() elif x == 2: menu.destroy() medium() elif x == 3: menu.destroy() difficult() else: pass letsgo = Button(menu_frame,text="Let's Go",bg="white",font="calibri 12",command=navigate) letsgo.place(relx=0.25,rely=0.8) menu.mainloop() def easy(): global e e = Tk() easy_canvas = Canvas(e,width=720,height=440,bg="#101357") easy_canvas.pack() easy_frame = Frame(easy_canvas,bg="white") easy_frame.place(relwidth=0.8,relheight=0.8,relx=0.1,rely=0.1) def countDown(): check = 0 for k in range(10, 0, -1): if k == 1: check=-1 timer.configure(text=k) easy_frame.update() time.sleep(1) timer.configure(text="Times up!") if check==-1: return (-1) else: return 0 global score score = 0 easyQ = [ [ "What will be the output of the following Python code? \nl=[1, 0, 2, 0, 'hello', '', []] \nlist(filter(bool, nl))", "[1, 0, 2, ‘hello’, '', []]", "Error", "[1, 2, ‘hello’]", "[1, 0, 2, 0, ‘hello’, '', []]" ] , [ "What will be the output of the following Python expression if the value of x is 34? \nprint(“%f”%x)" , "34.00", "34.000000", "34.0000", "34.00000000" ], [ "What will be the value of X in the following Python expression? \nX = 2+9*((3*12)-8)/10" , "30.8", "27.2", "28.4", "30.0" ], [ "Which of these in not a core data type?" , "Tuples", "Dictionary", "Lists", "Class" ], [ "Which of the following represents the bitwise XOR operator?" , "&", "!", "^", "|" ] ] answer = [ "[1, 2, ‘hello’]", "34.000000", "27.2", "Class", "^" ] li = ['',0,1,2,3,4] x = random.choice(li[1:]) ques = Label(easy_frame,text =easyQ[x][0],font="calibri 12",bg="white") ques.place(relx=0.5,rely=0.2,anchor=CENTER) var = StringVar() a = Radiobutton(easy_frame,text=easyQ[x][1],font="calibri 10",value=easyQ[x][1],variable = var,bg="white") a.place(relx=0.5,rely=0.42,anchor=CENTER) b = Radiobutton(easy_frame,text=easyQ[x][2],font="calibri 10",value=easyQ[x][2],variable = var,bg="white") b.place(relx=0.5,rely=0.52,anchor=CENTER) c = Radiobutton(easy_frame,text=easyQ[x][3],font="calibri 10",value=easyQ[x][3],variable = var,bg="white") c.place(relx=0.5,rely=0.62,anchor=CENTER) d = Radiobutton(easy_frame,text=easyQ[x][4],font="calibri 10",value=easyQ[x][4],variable = var,bg="white") d.place(relx=0.5,rely=0.72,anchor=CENTER) li.remove(x) timer = Label(e) timer.place(relx=0.8,rely=0.82,anchor=CENTER) def display(): if len(li) == 1: e.destroy() showMark(score) if len(li) == 2: nextQuestion.configure(text='End',command=calc) if li: x = random.choice(li[1:]) ques.configure(text =easyQ[x][0]) a.configure(text=easyQ[x][1],value=easyQ[x][1]) b.configure(text=easyQ[x][2],value=easyQ[x][2]) c.configure(text=easyQ[x][3],value=easyQ[x][3]) d.configure(text=easyQ[x][4],value=easyQ[x][4]) li.remove(x) print(li) y = countDown() if y == -1: display() def calc(): global score if (var.get() in answer): score+=1 display() submit = Button(easy_frame,command=calc,text="Submit") submit.place(relx=0.5,rely=0.82,anchor=CENTER) nextQuestion = Button(easy_frame,command=display,text="Next") nextQuestion.place(relx=0.87,rely=0.82,anchor=CENTER) y = countDown() if y == -1: display() e.mainloop() def medium(): global m m = Tk() med_canvas = Canvas(m,width=720,height=440,bg="#101357") med_canvas.pack() med_frame = Frame(med_canvas,bg="white") med_frame.place(relwidth=0.8,relheight=0.8,relx=0.1,rely=0.1) def countDown(): check = 0 for k in range(10, 0, -1): if k == 1: check=-1 timer.configure(text=k) med_frame.update() time.sleep(1) timer.configure(text="Times up!") if check==-1: return (-1) else: return 0 global score score = 0 mediumQ = [ [ "Which of the following is not an exception handling keyword in Python?", "accept", "finally", "except", "try" ], [ "Suppose list1 is [3, 5, 25, 1, 3], what is min(list1)?", "3", "5", "25", "1" ], [ "Suppose list1 is [2, 33, 222, 14, 25], What is list1[-1]?", "Error", "None", "25", "2" ], [ "print(0xA + 0xB + 0xC):", "0xA0xB0xC", "Error", "0x22", "33" ], [ "Which of the following is invalid?", "_a = 1", "__a = 1", "__str__ = 1", "none of the mentioned" ], ] answer = [ "accept", "1", "25", "33", "none of the mentioned" ] li = ['',0,1,2,3,4] x = random.choice(li[1:]) ques = Label(med_frame,text =mediumQ[x][0],font="calibri 12",bg="white") ques.place(relx=0.5,rely=0.2,anchor=CENTER) var = StringVar() a = Radiobutton(med_frame,text=mediumQ[x][1],font="calibri 10",value=mediumQ[x][1],variable = var,bg="white") a.place(relx=0.5,rely=0.42,anchor=CENTER) b = Radiobutton(med_frame,text=mediumQ[x][2],font="calibri 10",value=mediumQ[x][2],variable = var,bg="white") b.place(relx=0.5,rely=0.52,anchor=CENTER) c = Radiobutton(med_frame,text=mediumQ[x][3],font="calibri 10",value=mediumQ[x][3],variable = var,bg="white") c.place(relx=0.5,rely=0.62,anchor=CENTER) d = Radiobutton(med_frame,text=mediumQ[x][4],font="calibri 10",value=mediumQ[x][4],variable = var,bg="white") d.place(relx=0.5,rely=0.72,anchor=CENTER) li.remove(x) timer = Label(m) timer.place(relx=0.8,rely=0.82,anchor=CENTER) def display(): if len(li) == 1: m.destroy() showMark(score) if len(li) == 2: nextQuestion.configure(text='End',command=calc) if li: x = random.choice(li[1:]) ques.configure(text =mediumQ[x][0]) a.configure(text=mediumQ[x][1],value=mediumQ[x][1]) b.configure(text=mediumQ[x][2],value=mediumQ[x][2]) c.configure(text=mediumQ[x][3],value=mediumQ[x][3]) d.configure(text=mediumQ[x][4],value=mediumQ[x][4]) li.remove(x) print(li) y = countDown() if y == -1: display() def calc(): global score if (var.get() in answer): score+=1 display() submit = Button(med_frame,command=calc,text="Submit") submit.place(relx=0.5,rely=0.82,anchor=CENTER) nextQuestion = Button(med_frame,command=display,text="Next") nextQuestion.place(relx=0.87,rely=0.82,anchor=CENTER) y = countDown() if y == -1: display() m.mainloop() def difficult(): global h h = Tk() hard_canvas = Canvas(h,width=720,height=440,bg="#101357") hard_canvas.pack() hard_frame = Frame(hard_canvas,bg="white") hard_frame.place(relwidth=0.8,relheight=0.8,relx=0.1,rely=0.1) def countDown(): check = 0 for k in range(10, 0, -1): if k == 1: check=-1 timer.configure(text=k) hard_frame.update() time.sleep(1) timer.configure(text="Times up!") if check==-1: return (-1) else: return 0 global score score = 0 hardQ = [ [ "All keywords in Python are in _________", "lower case", "UPPER CASE", "Capitalized", "None of the mentioned" ], [ "Which of the following cannot be a variable?", "__init__", "in", "it", "on" ], [ "Which of the following is a Python tuple?", "[1, 2, 3]", "(1, 2, 3)", "{1, 2, 3}", "{}" ], [ "What is returned by math.ceil(3.4)?", "3", "4", "4.0", "3.0" ], [ "What will be the output of print(math.factorial(4.5))?", "24", "120", "error", "24.0" ] ] answer = [ "None of the mentioned", "in", "(1,2,3)", "4", "error" ] li = ['',0,1,2,3,4] x = random.choice(li[1:]) ques = Label(hard_frame,text =hardQ[x][0],font="calibri 12",bg="white") ques.place(relx=0.5,rely=0.2,anchor=CENTER) var = StringVar() a = Radiobutton(hard_frame,text=hardQ[x][1],font="calibri 10",value=hardQ[x][1],variable = var,bg="white") a.place(relx=0.5,rely=0.42,anchor=CENTER) b = Radiobutton(hard_frame,text=hardQ[x][2],font="calibri 10",value=hardQ[x][2],variable = var,bg="white") b.place(relx=0.5,rely=0.52,anchor=CENTER) c = Radiobutton(hard_frame,text=hardQ[x][3],font="calibri 10",value=hardQ[x][3],variable = var,bg="white") c.place(relx=0.5,rely=0.62,anchor=CENTER) d = Radiobutton(hard_frame,text=hardQ[x][4],font="calibri 10",value=hardQ[x][4],variable = var,bg="white") d.place(relx=0.5,rely=0.72,anchor=CENTER) li.remove(x) timer = Label(h) timer.place(relx=0.8,rely=0.82,anchor=CENTER) def display(): if len(li) == 1: h.destroy() showMark(score) if len(li) == 2: nextQuestion.configure(text='End',command=calc) if li: x = random.choice(li[1:]) ques.configure(text =hardQ[x][0]) a.configure(text=hardQ[x][1],value=hardQ[x][1]) b.configure(text=hardQ[x][2],value=hardQ[x][2]) c.configure(text=hardQ[x][3],value=hardQ[x][3]) d.configure(text=hardQ[x][4],value=hardQ[x][4]) li.remove(x) print(li) y = countDown() if y == -1: display() def calc(): global score if (var.get() in answer): score+=1 display() submit = Button(hard_frame,command=calc,text="Submit") submit.place(relx=0.5,rely=0.82,anchor=CENTER) nextQuestion = Button(hard_frame,command=display,text="Next") nextQuestion.place(relx=0.87,rely=0.82,anchor=CENTER) y = countDown() if y == -1: display() h.mainloop() def showMark(mark): global sh sh = Tk() show_canvas = Canvas(sh,width=720,height=440,bg="#101357") show_canvas.pack() show_frame = Frame(show_canvas,bg="white") show_frame.place(relwidth=0.8,relheight=0.8,relx=0.1,rely=0.1) st = "Your score is "+str(mark) mlabel = Label(show_canvas,text=st,fg="black") mlabel.place(relx=0.5,rely=0.2,anchor=CENTER) sh.mainloop() |
In this module which is the main module of the quiz game.
Complete Source Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 |
import tkinter as tk from tkinter import * import random import sqlite3 import time def loginPage(logdata): sup.destroy() global login login = Tk() user_name = StringVar() password = StringVar() login_canvas = Canvas(login,width=720,height=440,bg="blue") login_canvas.pack() login_frame = Frame(login_canvas,bg="white") login_frame.place(relwidth=0.8,relheight=0.8,relx=0.1,rely=0.1) heading = Label(login_frame,text="Quiz App Login",fg="black",bg="white") heading.config(font=('calibri 40')) heading.place(relx=0.2,rely=0.1) #USER NAME ulabel = Label(login_frame,text="Username",fg='black',bg='white') ulabel.place(relx=0.21,rely=0.4) uname = Entry(login_frame,bg='#d3d3d3',fg='black',textvariable = user_name) uname.config(width=42) uname.place(relx=0.31,rely=0.4) #PASSWORD plabel = Label(login_frame,text="Password",fg='black',bg='white') plabel.place(relx=0.215,rely=0.5) pas = Entry(login_frame,bg='#d3d3d3',fg='black',show="*",textvariable = password) pas.config(width=42) pas.place(relx=0.31,rely=0.5) def check(): for a,b,c,d in logdata: if b == uname.get() and c == pas.get(): menu() break else: error = Label(login_frame,text="Wrong Username or Password!",fg='black',bg='white') error.place(relx=0.37,rely=0.7) #LOGIN BUTTON log = Button(login_frame,text='Login',padx=5,pady=5,width=5,command=check) log.configure(width = 15,height=1, activebackground = "#33B5E5", relief = FLAT) log.place(relx=0.4,rely=0.6) login.mainloop() def signUpPage(): root.destroy() global sup sup = Tk() fname = StringVar() uname = StringVar() passW = StringVar() country = StringVar() sup_canvas = Canvas(sup,width=720,height=440,bg="blue") sup_canvas.pack() sup_frame = Frame(sup_canvas,bg="white") sup_frame.place(relwidth=0.8,relheight=0.8,relx=0.1,rely=0.1) heading = Label(sup_frame,text="Quiz App SignUp",fg="black",bg="white") heading.config(font=('calibri 40')) heading.place(relx=0.2,rely=0.1) #full name flabel = Label(sup_frame,text="Full Name",fg='black',bg='white') flabel.place(relx=0.21,rely=0.4) fname = Entry(sup_frame,bg='#d3d3d3',fg='black',textvariable = fname) fname.config(width=42) fname.place(relx=0.31,rely=0.4) #username ulabel = Label(sup_frame,text="Username",fg='black',bg='white') ulabel.place(relx=0.21,rely=0.5) user = Entry(sup_frame,bg='#d3d3d3',fg='black',textvariable = uname) user.config(width=42) user.place(relx=0.31,rely=0.5) #password plabel = Label(sup_frame,text="Password",fg='black',bg='white') plabel.place(relx=0.215,rely=0.6) pas = Entry(sup_frame,bg='#d3d3d3',fg='black',show="*",textvariable = passW) pas.config(width=42) pas.place(relx=0.31,rely=0.6) #country clabel = Label(sup_frame,text="Country",fg='black',bg='white') clabel.place(relx=0.215,rely=0.7) c = Entry(sup_frame,bg='#d3d3d3',fg='black',textvariable = country) c.config(width=42) c.place(relx=0.31,rely=0.7) def addUserToDataBase(): fullname = fname.get() username = user.get() password = pas.get() country = c.get() conn = sqlite3.connect('quiz.db') create = conn.cursor() create.execute('CREATE TABLE IF NOT EXISTS userSignUp(FULLNAME text, USERNAME text,PASSWORD text,COUNTRY text)') create.execute("INSERT INTO userSignUp VALUES (?,?,?,?)",(fullname,username,password,country)) conn.commit() create.execute('SELECT * FROM userSignUp') z=create.fetchall() print(z) # L2.config(text="Username is "+z[0][0]+"\nPassword is "+z[-1][1]) conn.close() loginPage(z) def gotoLogin(): conn = sqlite3.connect('quiz.db') create = conn.cursor() conn.commit() create.execute('SELECT * FROM userSignUp') z=create.fetchall() loginPage(z) #signup BUTTON sp = Button(sup_frame,text='SignUp',padx=5,pady=5,width=5,command = addUserToDataBase,bg='green') sp.configure(width = 15,height=1, activebackground = "#33B5E5", relief = FLAT) sp.place(relx=0.4,rely=0.8) log = Button(sup_frame,text='Already have a Account?',padx=5,pady=5,width=5,command = gotoLogin,bg="white",fg='blue') log.configure(width = 16,height=1, activebackground = "#33B5E5", relief = FLAT) log.place(relx=0.4,rely=0.9) sup.mainloop() def menu(): login.destroy() global menu menu = Tk() menu_canvas = Canvas(menu,width=720,height=440,bg="blue") menu_canvas.pack() menu_frame = Frame(menu_canvas,bg="white") menu_frame.place(relwidth=0.8,relheight=0.8,relx=0.1,rely=0.1) wel = Label(menu_canvas,text=' W E L C O M E T O Q U I Z S T A T I O N ',fg="white",bg="#101357") wel.config(font=('Broadway 22')) wel.place(relx=0.1,rely=0.02) level = Label(menu_frame,text='Select your Difficulty Level !!',bg="white",font="calibri 18") level.place(relx=0.25,rely=0.3) var = IntVar() easyR = Radiobutton(menu_frame,text='Easy',bg="white",font="calibri 16",value=1,variable = var) easyR.place(relx=0.25,rely=0.4) mediumR = Radiobutton(menu_frame,text='Medium',bg="white",font="calibri 16",value=2,variable = var) mediumR.place(relx=0.25,rely=0.5) hardR = Radiobutton(menu_frame,text='Hard',bg="white",font="calibri 16",value=3,variable = var) hardR.place(relx=0.25,rely=0.6) def navigate(): x = var.get() print(x) if x == 1: menu.destroy() easy() elif x == 2: menu.destroy() medium() elif x == 3: menu.destroy() difficult() else: pass letsgo = Button(menu_frame,text="Let's Go",bg="white",font="calibri 12",command=navigate) letsgo.place(relx=0.25,rely=0.8) menu.mainloop() def easy(): global e e = Tk() easy_canvas = Canvas(e,width=720,height=440,bg="#101357") easy_canvas.pack() easy_frame = Frame(easy_canvas,bg="white") easy_frame.place(relwidth=0.8,relheight=0.8,relx=0.1,rely=0.1) def countDown(): check = 0 for k in range(10, 0, -1): if k == 1: check=-1 timer.configure(text=k) easy_frame.update() time.sleep(1) timer.configure(text="Times up!") if check==-1: return (-1) else: return 0 global score score = 0 easyQ = [ [ "What will be the output of the following Python code? \nl=[1, 0, 2, 0, 'hello', '', []] \nlist(filter(bool, nl))", "[1, 0, 2, ‘hello’, '', []]", "Error", "[1, 2, ‘hello’]", "[1, 0, 2, 0, ‘hello’, '', []]" ] , [ "What will be the output of the following Python expression if the value of x is 34? \nprint(“%f”%x)" , "34.00", "34.000000", "34.0000", "34.00000000" ], [ "What will be the value of X in the following Python expression? \nX = 2+9*((3*12)-8)/10" , "30.8", "27.2", "28.4", "30.0" ], [ "Which of these in not a core data type?" , "Tuples", "Dictionary", "Lists", "Class" ], [ "Which of the following represents the bitwise XOR operator?" , "&", "!", "^", "|" ] ] answer = [ "[1, 2, ‘hello’]", "34.000000", "27.2", "Class", "^" ] li = ['',0,1,2,3,4] x = random.choice(li[1:]) ques = Label(easy_frame,text =easyQ[x][0],font="calibri 12",bg="white") ques.place(relx=0.5,rely=0.2,anchor=CENTER) var = StringVar() a = Radiobutton(easy_frame,text=easyQ[x][1],font="calibri 10",value=easyQ[x][1],variable = var,bg="white") a.place(relx=0.5,rely=0.42,anchor=CENTER) b = Radiobutton(easy_frame,text=easyQ[x][2],font="calibri 10",value=easyQ[x][2],variable = var,bg="white") b.place(relx=0.5,rely=0.52,anchor=CENTER) c = Radiobutton(easy_frame,text=easyQ[x][3],font="calibri 10",value=easyQ[x][3],variable = var,bg="white") c.place(relx=0.5,rely=0.62,anchor=CENTER) d = Radiobutton(easy_frame,text=easyQ[x][4],font="calibri 10",value=easyQ[x][4],variable = var,bg="white") d.place(relx=0.5,rely=0.72,anchor=CENTER) li.remove(x) timer = Label(e) timer.place(relx=0.8,rely=0.82,anchor=CENTER) def display(): if len(li) == 1: e.destroy() showMark(score) if len(li) == 2: nextQuestion.configure(text='End',command=calc) if li: x = random.choice(li[1:]) ques.configure(text =easyQ[x][0]) a.configure(text=easyQ[x][1],value=easyQ[x][1]) b.configure(text=easyQ[x][2],value=easyQ[x][2]) c.configure(text=easyQ[x][3],value=easyQ[x][3]) d.configure(text=easyQ[x][4],value=easyQ[x][4]) li.remove(x) print(li) y = countDown() if y == -1: display() def calc(): global score if (var.get() in answer): score+=1 display() submit = Button(easy_frame,command=calc,text="Submit") submit.place(relx=0.5,rely=0.82,anchor=CENTER) nextQuestion = Button(easy_frame,command=display,text="Next") nextQuestion.place(relx=0.87,rely=0.82,anchor=CENTER) y = countDown() if y == -1: display() e.mainloop() def medium(): global m m = Tk() med_canvas = Canvas(m,width=720,height=440,bg="#101357") med_canvas.pack() med_frame = Frame(med_canvas,bg="white") med_frame.place(relwidth=0.8,relheight=0.8,relx=0.1,rely=0.1) def countDown(): check = 0 for k in range(10, 0, -1): if k == 1: check=-1 timer.configure(text=k) med_frame.update() time.sleep(1) timer.configure(text="Times up!") if check==-1: return (-1) else: return 0 global score score = 0 mediumQ = [ [ "Which of the following is not an exception handling keyword in Python?", "accept", "finally", "except", "try" ], [ "Suppose list1 is [3, 5, 25, 1, 3], what is min(list1)?", "3", "5", "25", "1" ], [ "Suppose list1 is [2, 33, 222, 14, 25], What is list1[-1]?", "Error", "None", "25", "2" ], [ "print(0xA + 0xB + 0xC):", "0xA0xB0xC", "Error", "0x22", "33" ], [ "Which of the following is invalid?", "_a = 1", "__a = 1", "__str__ = 1", "none of the mentioned" ], ] answer = [ "accept", "1", "25", "33", "none of the mentioned" ] li = ['',0,1,2,3,4] x = random.choice(li[1:]) ques = Label(med_frame,text =mediumQ[x][0],font="calibri 12",bg="white") ques.place(relx=0.5,rely=0.2,anchor=CENTER) var = StringVar() a = Radiobutton(med_frame,text=mediumQ[x][1],font="calibri 10",value=mediumQ[x][1],variable = var,bg="white") a.place(relx=0.5,rely=0.42,anchor=CENTER) b = Radiobutton(med_frame,text=mediumQ[x][2],font="calibri 10",value=mediumQ[x][2],variable = var,bg="white") b.place(relx=0.5,rely=0.52,anchor=CENTER) c = Radiobutton(med_frame,text=mediumQ[x][3],font="calibri 10",value=mediumQ[x][3],variable = var,bg="white") c.place(relx=0.5,rely=0.62,anchor=CENTER) d = Radiobutton(med_frame,text=mediumQ[x][4],font="calibri 10",value=mediumQ[x][4],variable = var,bg="white") d.place(relx=0.5,rely=0.72,anchor=CENTER) li.remove(x) timer = Label(m) timer.place(relx=0.8,rely=0.82,anchor=CENTER) def display(): if len(li) == 1: m.destroy() showMark(score) if len(li) == 2: nextQuestion.configure(text='End',command=calc) if li: x = random.choice(li[1:]) ques.configure(text =mediumQ[x][0]) a.configure(text=mediumQ[x][1],value=mediumQ[x][1]) b.configure(text=mediumQ[x][2],value=mediumQ[x][2]) c.configure(text=mediumQ[x][3],value=mediumQ[x][3]) d.configure(text=mediumQ[x][4],value=mediumQ[x][4]) li.remove(x) print(li) y = countDown() if y == -1: display() def calc(): global score if (var.get() in answer): score+=1 display() submit = Button(med_frame,command=calc,text="Submit") submit.place(relx=0.5,rely=0.82,anchor=CENTER) nextQuestion = Button(med_frame,command=display,text="Next") nextQuestion.place(relx=0.87,rely=0.82,anchor=CENTER) y = countDown() if y == -1: display() m.mainloop() def difficult(): global h h = Tk() hard_canvas = Canvas(h,width=720,height=440,bg="#101357") hard_canvas.pack() hard_frame = Frame(hard_canvas,bg="white") hard_frame.place(relwidth=0.8,relheight=0.8,relx=0.1,rely=0.1) def countDown(): check = 0 for k in range(10, 0, -1): if k == 1: check=-1 timer.configure(text=k) hard_frame.update() time.sleep(1) timer.configure(text="Times up!") if check==-1: return (-1) else: return 0 global score score = 0 hardQ = [ [ "All keywords in Python are in _________", "lower case", "UPPER CASE", "Capitalized", "None of the mentioned" ], [ "Which of the following cannot be a variable?", "__init__", "in", "it", "on" ], [ "Which of the following is a Python tuple?", "[1, 2, 3]", "(1, 2, 3)", "{1, 2, 3}", "{}" ], [ "What is returned by math.ceil(3.4)?", "3", "4", "4.0", "3.0" ], [ "What will be the output of print(math.factorial(4.5))?", "24", "120", "error", "24.0" ] ] answer = [ "None of the mentioned", "in", "(1,2,3)", "4", "error" ] li = ['',0,1,2,3,4] x = random.choice(li[1:]) ques = Label(hard_frame,text =hardQ[x][0],font="calibri 12",bg="white") ques.place(relx=0.5,rely=0.2,anchor=CENTER) var = StringVar() a = Radiobutton(hard_frame,text=hardQ[x][1],font="calibri 10",value=hardQ[x][1],variable = var,bg="white") a.place(relx=0.5,rely=0.42,anchor=CENTER) b = Radiobutton(hard_frame,text=hardQ[x][2],font="calibri 10",value=hardQ[x][2],variable = var,bg="white") b.place(relx=0.5,rely=0.52,anchor=CENTER) c = Radiobutton(hard_frame,text=hardQ[x][3],font="calibri 10",value=hardQ[x][3],variable = var,bg="white") c.place(relx=0.5,rely=0.62,anchor=CENTER) d = Radiobutton(hard_frame,text=hardQ[x][4],font="calibri 10",value=hardQ[x][4],variable = var,bg="white") d.place(relx=0.5,rely=0.72,anchor=CENTER) li.remove(x) timer = Label(h) timer.place(relx=0.8,rely=0.82,anchor=CENTER) def display(): if len(li) == 1: h.destroy() showMark(score) if len(li) == 2: nextQuestion.configure(text='End',command=calc) if li: x = random.choice(li[1:]) ques.configure(text =hardQ[x][0]) a.configure(text=hardQ[x][1],value=hardQ[x][1]) b.configure(text=hardQ[x][2],value=hardQ[x][2]) c.configure(text=hardQ[x][3],value=hardQ[x][3]) d.configure(text=hardQ[x][4],value=hardQ[x][4]) li.remove(x) print(li) y = countDown() if y == -1: display() def calc(): global score if (var.get() in answer): score+=1 display() submit = Button(hard_frame,command=calc,text="Submit") submit.place(relx=0.5,rely=0.82,anchor=CENTER) nextQuestion = Button(hard_frame,command=display,text="Next") nextQuestion.place(relx=0.87,rely=0.82,anchor=CENTER) y = countDown() if y == -1: display() h.mainloop() def showMark(mark): global sh sh = Tk() show_canvas = Canvas(sh,width=720,height=440,bg="#101357") show_canvas.pack() show_frame = Frame(show_canvas,bg="white") show_frame.place(relwidth=0.8,relheight=0.8,relx=0.1,rely=0.1) st = "Your score is "+str(mark) mlabel = Label(show_canvas,text=st,fg="black") mlabel.place(relx=0.5,rely=0.2,anchor=CENTER) sh.mainloop() def start(): global root root = Tk() canvas = Canvas(root,width = 720,height = 440) canvas.grid(column = 0 , row = 1) img = PhotoImage(file="back.png") canvas.create_image(50,10,image=img,anchor=NW) button = Button(root, text='Start',command = signUpPage) button.configure(width = 102,height=2, activebackground = "#33B5E5", bg ='green', relief = RAISED) button.grid(column = 0 , row = 2) root.mainloop() if __name__=='__main__': start() |
Output



Run Quick Virus Scan for secure Download
Run Quick Scan for secure DownloadDownloadable Source Code
I have here the list of Best Python Project with Source code free to download for free, I hope this can help you a lot.
Summary
The Quiz Application In Python is written in Python programming language, Python is very smooth to research the syntax emphasizes readability and it is able to reduces time ingesting in developing.
Also in this tutorial is the simplest way for the beginners or the student to enhance their logical skills in programming. and also in this game project is the way for the students or beginners in designing and developing games.
The project Quiz In Python contains only the user side. The user must log in or sign up first to start the Quiz On Python. Also, there is a time duration set for solving the questions. The user should solve the questions before time is up.
Related Articles
- Snakes and Ladders Game in Python with Source Code
- Code For Game in Python: Python Game Projects With Source Code
- Stickman Game in Python with Source Code
- Tank Game Python with Source Code
- Tetris In Python Code
- Mario Game In Python With Source Code
- Hangman Game In Python With Source Code
- Aircraft War Game in Python with Source Code
- Snake Game In Python Code
- How to Make Bouncing Ball Game in Python with Source Code
- How to Create Rock-Paper-Scissor Game in Python
Inquiries
If you have any questions or suggestions about Quiz Application In Python , please feel free to leave a comment below.
do u have any report sir pls forward us
if we don’t want login and signup page which changes we have to make?
and sup.destory() is for what?