Skip to content

Basic Quiz Game

Abstract

Basic Quiz Game is an interactive Python application that presents multiple-choice questions about world capitals through a graphical user interface. Built with Tkinter, the application features question navigation, score tracking, answer validation, and various control options including shuffle, reset, and back functionality. This project demonstrates GUI development, data management, user interaction handling, and educational software design principles.

Prerequisites

  • Python 3.6 or above
  • A code editor or IDE
  • tkinter module (usually comes pre-installed)

Before you Start

Before starting this project, you must have Python installed on your computer. If you don’t have Python installed, you can download it from here. You must have a code editor or IDE installed on your computer. If you don’t have any code editor or IDE installed, you can download Visual Studio Code from here.

Note: This project uses only built-in Python modules, so no additional installations are required.

Getting Started

Create a Project

  1. Create a folder named quiz-gamequiz-game.
  2. Open the folder in your favorite code editor or IDE.
  3. Create a file named quizapp.pyquizapp.py.
  4. Copy the given code and paste it in your quizapp.pyquizapp.py file.

Write the Code

  1. Copy and paste the following code in your quizapp.pyquizapp.py file.
⚙️ Basic Quiz Game
Basic Quiz Game
# Basic Quiz App
 
# Importing Modules
from tkinter import *
from tkinter import messagebox
import random
 
# Creating Root Window
root = Tk()
root.title("Quiz App")
root.geometry("500x500")
root.resizable(0, 0)
root.config(bg="white")
 
# Creating Variables
score = 0
ques = 1
ques_num = 1
ans = 0
ans_list = []
 
# Creating Questions
questions = [
    "What is the Capital of India?",
    "What is the Capital of USA?",
    "What is the Capital of UK?",
    "What is the Capital of China?",
    "What is the Capital of Japan?",
    "What is the Capital of Russia?",
    "What is the Capital of France?",
    "What is the Capital of Germany?",
    "What is the Capital of Brazil?",
    "What is the Capital of Australia?",
]
 
# Creating Options
options = [
    ["New Delhi", "Mumbai", "Kolkata", "Chennai"],
    ["New York", "Washington DC", "California", "Texas"],
    ["London", "Manchester", "Liverpool", "Birmingham"],
    ["Beijing", "Shanghai", "Hong Kong", "Wuhan"],
    ["Tokyo", "Osaka", "Kyoto", "Yokohama"],
    ["Moscow", "Saint Petersburg", "Novosibirsk", "Yekaterinburg"],
    ["Paris", "Lyon", "Marseille", "Toulouse"],
    ["Berlin", "Hamburg", "Munich", "Cologne"],
    ["Brasilia", "Rio de Janeiro", "Sao Paulo", "Salvador"],
    ["Sydney", "Melbourne", "Perth", "Brisbane"],
]
 
# Creating Answers
answers = [0, 1, 0, 0, 0, 0, 0, 0, 0, 0]
 
# Creating Functions
def selected():
    global ans, radio
    global ques_num, ques
    global score, ans_list
    x = 0
    y = 50
    if ques_num == 10:
        submit.config(text="Finish")
    if ans == answers[ques_num - 1]:
        score += 1
        ans_list.append(1)
    else:
        ans_list.append(0)
    ques_num += 1
    ques.config(text=questions[ques_num - 1])
    for i in range(4):
        radio[i].config(text=options[ques_num - 1][i])
    if ques_num == 11:
        messagebox.showinfo("Score", f"Your Score is {score}")
        root.destroy()
        
def submit():
    global ques_num, score, ans_list
    if ques_num == 10:
        submit.config(text="Finish")
    if ans == answers[ques_num - 1]:
        score += 1
        ans_list.append(1)
    else:
        ans_list.append(0)
    ques_num += 1
    ques.config(text=questions[ques_num - 1])
    for i in range(4):
        radio[i].config(text=options[ques_num - 1][i])
    if ques_num == 11:
        messagebox.showinfo("Score", f"Your Score is {score}")
        root.destroy()
        
def back():
    global ques_num, score, ans_list
    if ques_num == 1:
        messagebox.showinfo("Error", "You are at the first question")
    else:
        ques_num -= 1
        score -= ans_list[ques_num - 1]
        ques.config(text=questions[ques_num - 1])
        for i in range(4):
            radio[i].config(text=options[ques_num - 1][i])
        if ques_num == 10:
            submit.config(text="Finish")
        else:
            submit.config(text="Next")
            
def reset():
    global ques_num, score, ans_list
    ques_num = 1
    score = 0
    ans_list = []
    ques.config(text=questions[ques_num - 1])
    for i in range(4):
        radio[i].config(text=options[ques_num - 1][i])
    submit.config(text="Next")
    
def check():
    global ans
    ans = v.get()
    
def shuffle():
    global questions, options, answers
    x = list(zip(questions, options, answers))
    random.shuffle(x)
    questions, options, answers = zip(*x)
    ques.config(text=questions[ques_num - 1])
    for i in range(4):
        radio[i].config(text=options[ques_num - 1][i])
        
def show():
    global ques_num, score, ans_list
    messagebox.showinfo("Score", f"Your Score is {score}")
    root.destroy()
    
# Creating Labels
ques = Label(root, text=questions[ques_num - 1], font=("Helvetica", 20), bg="white")
ques.place(x=50, y=50)
 
# Creating Radio Buttons
v = IntVar()
radio = []
for i in range(4):
    radio.append(Radiobutton(root, text=options[ques_num - 1][i], font=("Helvetica", 20), bg="white", variable=v, value=i, command=check))
    radio[i].place(x=50, y=100 + i * 50)
    
# Creating Buttons
submit = Button(root, text="Next", font=("Helvetica", 20), bg="white", command=submit)
submit.place(x=50, y=300)
back = Button(root, text="Back", font=("Helvetica", 20), bg="white", command=back)
back.place(x=150, y=300)
reset = Button(root, text="Reset", font=("Helvetica", 20), bg="white", command=reset)
reset.place(x=250, y=300)
shuffle = Button(root, text="Shuffle", font=("Helvetica", 20), bg="white", command=shuffle)
shuffle.place(x=350, y=300)
show = Button(root, text="Show Score", font=("Helvetica", 20), bg="white", command=show)
show.place(x=50, y=400)
 
# Running Root Window
root.mainloop() 
Basic Quiz Game
# Basic Quiz App
 
# Importing Modules
from tkinter import *
from tkinter import messagebox
import random
 
# Creating Root Window
root = Tk()
root.title("Quiz App")
root.geometry("500x500")
root.resizable(0, 0)
root.config(bg="white")
 
# Creating Variables
score = 0
ques = 1
ques_num = 1
ans = 0
ans_list = []
 
# Creating Questions
questions = [
    "What is the Capital of India?",
    "What is the Capital of USA?",
    "What is the Capital of UK?",
    "What is the Capital of China?",
    "What is the Capital of Japan?",
    "What is the Capital of Russia?",
    "What is the Capital of France?",
    "What is the Capital of Germany?",
    "What is the Capital of Brazil?",
    "What is the Capital of Australia?",
]
 
# Creating Options
options = [
    ["New Delhi", "Mumbai", "Kolkata", "Chennai"],
    ["New York", "Washington DC", "California", "Texas"],
    ["London", "Manchester", "Liverpool", "Birmingham"],
    ["Beijing", "Shanghai", "Hong Kong", "Wuhan"],
    ["Tokyo", "Osaka", "Kyoto", "Yokohama"],
    ["Moscow", "Saint Petersburg", "Novosibirsk", "Yekaterinburg"],
    ["Paris", "Lyon", "Marseille", "Toulouse"],
    ["Berlin", "Hamburg", "Munich", "Cologne"],
    ["Brasilia", "Rio de Janeiro", "Sao Paulo", "Salvador"],
    ["Sydney", "Melbourne", "Perth", "Brisbane"],
]
 
# Creating Answers
answers = [0, 1, 0, 0, 0, 0, 0, 0, 0, 0]
 
# Creating Functions
def selected():
    global ans, radio
    global ques_num, ques
    global score, ans_list
    x = 0
    y = 50
    if ques_num == 10:
        submit.config(text="Finish")
    if ans == answers[ques_num - 1]:
        score += 1
        ans_list.append(1)
    else:
        ans_list.append(0)
    ques_num += 1
    ques.config(text=questions[ques_num - 1])
    for i in range(4):
        radio[i].config(text=options[ques_num - 1][i])
    if ques_num == 11:
        messagebox.showinfo("Score", f"Your Score is {score}")
        root.destroy()
        
def submit():
    global ques_num, score, ans_list
    if ques_num == 10:
        submit.config(text="Finish")
    if ans == answers[ques_num - 1]:
        score += 1
        ans_list.append(1)
    else:
        ans_list.append(0)
    ques_num += 1
    ques.config(text=questions[ques_num - 1])
    for i in range(4):
        radio[i].config(text=options[ques_num - 1][i])
    if ques_num == 11:
        messagebox.showinfo("Score", f"Your Score is {score}")
        root.destroy()
        
def back():
    global ques_num, score, ans_list
    if ques_num == 1:
        messagebox.showinfo("Error", "You are at the first question")
    else:
        ques_num -= 1
        score -= ans_list[ques_num - 1]
        ques.config(text=questions[ques_num - 1])
        for i in range(4):
            radio[i].config(text=options[ques_num - 1][i])
        if ques_num == 10:
            submit.config(text="Finish")
        else:
            submit.config(text="Next")
            
def reset():
    global ques_num, score, ans_list
    ques_num = 1
    score = 0
    ans_list = []
    ques.config(text=questions[ques_num - 1])
    for i in range(4):
        radio[i].config(text=options[ques_num - 1][i])
    submit.config(text="Next")
    
def check():
    global ans
    ans = v.get()
    
def shuffle():
    global questions, options, answers
    x = list(zip(questions, options, answers))
    random.shuffle(x)
    questions, options, answers = zip(*x)
    ques.config(text=questions[ques_num - 1])
    for i in range(4):
        radio[i].config(text=options[ques_num - 1][i])
        
def show():
    global ques_num, score, ans_list
    messagebox.showinfo("Score", f"Your Score is {score}")
    root.destroy()
    
# Creating Labels
ques = Label(root, text=questions[ques_num - 1], font=("Helvetica", 20), bg="white")
ques.place(x=50, y=50)
 
# Creating Radio Buttons
v = IntVar()
radio = []
for i in range(4):
    radio.append(Radiobutton(root, text=options[ques_num - 1][i], font=("Helvetica", 20), bg="white", variable=v, value=i, command=check))
    radio[i].place(x=50, y=100 + i * 50)
    
# Creating Buttons
submit = Button(root, text="Next", font=("Helvetica", 20), bg="white", command=submit)
submit.place(x=50, y=300)
back = Button(root, text="Back", font=("Helvetica", 20), bg="white", command=back)
back.place(x=150, y=300)
reset = Button(root, text="Reset", font=("Helvetica", 20), bg="white", command=reset)
reset.place(x=250, y=300)
shuffle = Button(root, text="Shuffle", font=("Helvetica", 20), bg="white", command=shuffle)
shuffle.place(x=350, y=300)
show = Button(root, text="Show Score", font=("Helvetica", 20), bg="white", command=show)
show.place(x=50, y=400)
 
# Running Root Window
root.mainloop() 
  1. Save the file.
  2. Open the terminal in your code editor or IDE and navigate to the folder quiz-gamequiz-game.
command
C:\Users\Your Name\quiz-game> python quizapp.py
# A GUI window will open with:
# - Question display area
# - Four multiple-choice radio buttons
# - Navigation buttons (Next, Back, Reset, Shuffle)
# - Show Score button
# - Score tracking functionality
 
# Example quiz flow:
Question 1: "What is the Capital of India?"
Options: New Delhi, Mumbai, Kolkata, Chennai
Select answer → Click NextContinue to next question
Final Score: "Your Score is 8/10"
command
C:\Users\Your Name\quiz-game> python quizapp.py
# A GUI window will open with:
# - Question display area
# - Four multiple-choice radio buttons
# - Navigation buttons (Next, Back, Reset, Shuffle)
# - Show Score button
# - Score tracking functionality
 
# Example quiz flow:
Question 1: "What is the Capital of India?"
Options: New Delhi, Mumbai, Kolkata, Chennai
Select answer → Click NextContinue to next question
Final Score: "Your Score is 8/10"

Explanation

Code Structure Overview

The quiz application is organized into several key components:

  1. Data Structure: Questions, options, and answers arrays
  2. GUI Components: Labels, radio buttons, and control buttons
  3. Navigation Logic: Forward/backward movement through questions
  4. Score Management: Tracking correct answers and displaying results

Data Setup

  1. Import modules and create main window.
quizapp.py
from tkinter import *
from tkinter import messagebox
import random
 
root = Tk()
root.title("Quiz App")
root.geometry("500x500")
root.resizable(0, 0)
quizapp.py
from tkinter import *
from tkinter import messagebox
import random
 
root = Tk()
root.title("Quiz App")
root.geometry("500x500")
root.resizable(0, 0)
  1. Initialize quiz data structures.
quizapp.py
questions = [
    "What is the Capital of India?",
    "What is the Capital of USA?",
    "What is the Capital of UK?",
    # ... more questions
]
 
options = [
    ["New Delhi", "Mumbai", "Kolkata", "Chennai"],
    ["New York", "Washington DC", "California", "Texas"],
    # ... corresponding options
]
 
answers = [0, 1, 0, 0, 0, 0, 0, 0, 0, 0]  # Index of correct answers
quizapp.py
questions = [
    "What is the Capital of India?",
    "What is the Capital of USA?",
    "What is the Capital of UK?",
    # ... more questions
]
 
options = [
    ["New Delhi", "Mumbai", "Kolkata", "Chennai"],
    ["New York", "Washington DC", "California", "Texas"],
    # ... corresponding options
]
 
answers = [0, 1, 0, 0, 0, 0, 0, 0, 0, 0]  # Index of correct answers
  1. Core navigation and scoring logic.
quizapp.py
def selected():
    global ans, ques_num, score, ans_list
    if ques_num == 10:
        submit.config(text="Finish")
    if ans == answers[ques_num - 1]:
        score += 1
        ans_list.append(1)
    else:
        ans_list.append(0)
    ques_num += 1
    ques.config(text=questions[ques_num - 1])
    for i in range(4):
        radio[i].config(text=options[ques_num - 1][i])
    if ques_num == 11:
        messagebox.showinfo("Score", f"Your Score is {score}")
        root.destroy()
quizapp.py
def selected():
    global ans, ques_num, score, ans_list
    if ques_num == 10:
        submit.config(text="Finish")
    if ans == answers[ques_num - 1]:
        score += 1
        ans_list.append(1)
    else:
        ans_list.append(0)
    ques_num += 1
    ques.config(text=questions[ques_num - 1])
    for i in range(4):
        radio[i].config(text=options[ques_num - 1][i])
    if ques_num == 11:
        messagebox.showinfo("Score", f"Your Score is {score}")
        root.destroy()

Features

  • 10 Geography Questions: World capitals quiz covering major countries
  • Multiple Choice Interface: Four options per question with radio button selection
  • Score Tracking: Real-time scoring with final results display
  • Navigation Controls: Next, Back, Reset, and Shuffle functionality
  • Question Shuffling: Randomize question order for variety
  • Answer Validation: Automatic checking and score calculation
  • User-Friendly Interface: Clean design with intuitive controls

Quiz Questions Covered

The application includes questions about capitals of:

  1. India → New Delhi
  2. USA → Washington DC
  3. UK → London
  4. China → Beijing
  5. Japan → Tokyo
  6. Russia → Moscow
  7. France → Paris
  8. Germany → Berlin
  9. Brazil → Brasilia
  10. Australia → Canberra (Sydney in options)

Control Functions

  • Next/Submit: Move to next question or finish quiz
  • Back: Return to previous question (with score adjustment)
  • Reset: Restart quiz from the beginning
  • Shuffle: Randomize question order

Scoring Functions

  • Real-time Tracking: Score updates as questions are answered
  • Answer History: Maintains record of correct/incorrect responses
  • Final Display: Shows total score at quiz completion

How to Use

  1. Start Quiz: Launch the application to see the first question
  2. Select Answer: Click on one of the four radio button options
  3. Navigate: Use Next/Back buttons to move through questions
  4. View Progress: Current question number and score are tracked
  5. Shuffle Questions: Click Shuffle to randomize question order
  6. Reset: Start over at any time with the Reset button
  7. Finish: Complete all questions to see final score
  8. Show Score: View current score at any time

GUI Layout

┌─────────────────────────────────────┐
│          Quiz Question              │
├─────────────────────────────────────┤
│  ○ Option A                        │
│  ○ Option B                        │
│  ○ Option C                        │
│  ○ Option D                        │
├─────────────────────────────────────┤
│ [Next] [Back] [Reset] [Shuffle]    │
│ [Show Score]                       │
└─────────────────────────────────────┘
┌─────────────────────────────────────┐
│          Quiz Question              │
├─────────────────────────────────────┤
│  ○ Option A                        │
│  ○ Option B                        │
│  ○ Option C                        │
│  ○ Option D                        │
├─────────────────────────────────────┤
│ [Next] [Back] [Reset] [Shuffle]    │
│ [Show Score]                       │
└─────────────────────────────────────┘

Next Steps

You can enhance this project by:

  • Adding more question categories (Science, History, Sports)
  • Implementing a timer for each question
  • Creating difficulty levels (Easy, Medium, Hard)
  • Adding images or multimedia to questions
  • Implementing user registration and profile saving
  • Creating a question bank with random selection
  • Adding detailed explanations for answers
  • Implementing multiple quiz modes (Timed, Survival, Practice)
  • Creating leaderboards and high scores
  • Adding sound effects and animations

Enhanced Features Ideas

quizapp.py
def enhanced_quiz():
    # Features to add:
    # - Question categories and filtering
    # - Timer functionality
    # - Detailed result analysis
    # - User profiles and progress tracking
    # - Question difficulty ratings
    # - Multimedia support
    pass
 
class QuizQuestion:
    def __init__(self, question, options, answer, category, difficulty):
        self.question = question
        self.options = options
        self.answer = answer
        self.category = category
        self.difficulty = difficulty
quizapp.py
def enhanced_quiz():
    # Features to add:
    # - Question categories and filtering
    # - Timer functionality
    # - Detailed result analysis
    # - User profiles and progress tracking
    # - Question difficulty ratings
    # - Multimedia support
    pass
 
class QuizQuestion:
    def __init__(self, question, options, answer, category, difficulty):
        self.question = question
        self.options = options
        self.answer = answer
        self.category = category
        self.difficulty = difficulty

Educational Applications

  • Geography Learning: World capitals and countries
  • Academic Testing: Create subject-specific quizzes
  • Training Programs: Employee knowledge assessment
  • Language Learning: Vocabulary and grammar tests
  • Certification Prep: Practice exams for various fields

Customization Options

Adding New Questions

quizapp.py
new_questions = [
    "What is the largest planet?",
    "Who wrote Romeo and Juliet?",
    # Add more questions
]
 
new_options = [
    ["Earth", "Jupiter", "Saturn", "Mars"],
    ["Shakespeare", "Dickens", "Austen", "Tolkien"],
    # Add corresponding options
]
 
new_answers = [1, 0]  # Index of correct answers
quizapp.py
new_questions = [
    "What is the largest planet?",
    "Who wrote Romeo and Juliet?",
    # Add more questions
]
 
new_options = [
    ["Earth", "Jupiter", "Saturn", "Mars"],
    ["Shakespeare", "Dickens", "Austen", "Tolkien"],
    # Add corresponding options
]
 
new_answers = [1, 0]  # Index of correct answers

Styling Improvements

quizapp.py
# Enhanced styling options
root.config(bg="#f0f0f0")
question_font = ("Arial", 16, "bold")
option_font = ("Arial", 12)
button_style = {"font": ("Arial", 10), "bg": "#4CAF50", "fg": "white"}
quizapp.py
# Enhanced styling options
root.config(bg="#f0f0f0")
question_font = ("Arial", 16, "bold")
option_font = ("Arial", 12)
button_style = {"font": ("Arial", 10), "bg": "#4CAF50", "fg": "white"}

Educational Value

This project teaches:

  • GUI Development: Creating interactive desktop applications
  • Data Management: Organizing questions, options, and answers
  • Event Handling: Managing user interactions and button clicks
  • State Management: Tracking quiz progress and scoring
  • User Experience Design: Creating intuitive interfaces

Common Enhancements

  • Timer Implementation: Add countdown for each question
  • Category Selection: Allow users to choose question topics
  • Difficulty Levels: Implement easy, medium, hard questions
  • Results Analysis: Show detailed performance statistics
  • Data Persistence: Save scores and progress to files

Real-World Applications

  • Educational Software: Classroom quiz applications
  • Training Systems: Corporate knowledge testing
  • Certification Tools: Practice exams for licenses/certifications
  • Entertainment: Trivia games and brain teasers
  • Assessment Tools: Academic evaluation software

Performance Considerations

  • Memory Usage: Efficient data structure management
  • Response Time: Quick GUI updates and navigation
  • Scalability: Easy addition of new questions and categories
  • User Experience: Smooth interaction and feedback

Conclusion

In this project, we learned how to create a Basic Quiz Game using Python’s Tkinter library. We explored GUI development, data management, event handling, and user interaction design. This project demonstrates how to create engaging educational software with proper navigation controls and scoring systems. The quiz application serves as an excellent foundation for more complex educational applications and can be easily customized for different subjects and learning objectives. To find more projects like this, you can visit Python Central Hub.

Was this page helpful?

Let us know how we did