← Back to Projects
MkViewer - Quizzler [Read-Only]
Initializing MkViewer...
README.md

Day 34 - Quizzler β€” True/False Trivia Quiz (Tkinter)

A simple GUI quiz app that pulls True/False questions from an online API and lets you answer them in a clean interface.

README GENERATED BY AI


🧠 Overview

This project is a Python quiz application built with Tkinter and requests.
When you run it, the app:

  • Fetches 10 random True/False questions from the Open Trivia DB API
  • Displays one question at a time in a Tkinter window
  • Lets you answer using βœ… True / ❌ False buttons
  • Keeps track of your current score
  • Shows a completion message when you finish the quiz

It’s a great example of combining:

  • API calls
  • Object-oriented design (Question, QuizBrain, QuizInterface)
  • A graphical UI with Tkinter

πŸ—‚ Project Structure

```text . β”œβ”€β”€ main.py # Entry point: fetches questions and starts the quiz β”œβ”€β”€ ui.py # Tkinter UI: QuizInterface class, buttons, labels, canvas β”œβ”€β”€ question_model.py # Question class (models a single question) β”œβ”€β”€ quiz_brain.py # QuizBrain class (quiz logic, scoring, question flow) └── images/ β”œβ”€β”€ true.png # True button image └── false.png # False button image ````

Note: Only main.py and ui.py are shown here, but question_model.py and quiz_brain.py are small helper modules.


βš™οΈ Requirements

  • Python 3.10+ (earlier versions likely fine too)
  • The following Python packages:

  • requests (for the API call)

  • tkinter (comes with most Python installations)

Install requests with:

bash pip install requests

You’ll also need:

  • images/true.png
  • images/false.png

in an images folder next to your .py files.


πŸš€ How to Run

  1. Make sure the project files are in the same folder:

text main.py ui.py question_model.py quiz_brain.py /images β”œβ”€β”€ true.png └── false.png

  1. Install dependencies:

bash pip install requests

  1. Run the main script:

bash python main.py

  1. A window titled β€œQuizzler” should appear.

🧩 How It Works (High-Level)

main.py

  • Calls the Open Trivia DB API:

python question_data = requests.get( url="https://opentdb.com/api.php?amount=10&type=boolean" ).json()["results"]

  • Builds a question_bank list of Question objects.

  • Creates a QuizBrain instance to handle quiz logic.

  • Passes QuizBrain into QuizInterface to start the GUI.

  • (There’s also a CLI-style while quiz.still_has_questions() loop at the bottom, but the GUI handles most of the interaction now.)

ui.py β€” QuizInterface

  • Sets up the Tkinter window:

  • Title: "Quizzler"

  • Background color: THEME_COLOR = "#375362"
  • Score label in the top-right
  • Canvas in the center to display the question text
  • Two image buttons:

    • βœ… True (true.png)
    • ❌ False (false.png)
  • Calls self.get_next_question() to load the first question.

  • When you click a button, it calls:

python self.check_answer(True) # or False

  • Uses methods on the QuizBrain instance (like next_question() and check_answer(...)) to:

  • Move to the next question

  • Update the score
  • Detect when the quiz is finished

βœ… Features

  • Fetches live questions from an online trivia API
  • Simple, intuitive True/False interface
  • Score tracking in the UI
  • End-of-quiz message when you finish all 10 questions
  • Clean separation of:

  • Data model (Question)

  • Logic (QuizBrain)
  • UI (QuizInterface)

πŸ’‘ Possible Improvements

Some ideas if you want to expand this project later:

  • Add a difficulty selector (easy/medium/hard) using the API’s parameters
  • Let the user pick number of questions
  • Show feedback colors (e.g., green for correct, red for wrong) for a second before moving on
  • Add categories (e.g., film, science, history)
  • Store high scores in a local file (e.g., JSON or text)
  • Add a β€œPlay Again” button when the quiz ends

🧾 Notes

  • This project was written in Python and uses Tkinter for the GUI.
  • Trivia data is provided by the Open Trivia Database (https://opentdb.com/api_config.php).
  • README GENERATED BY AI
  • This was actually a modified version of 'The Quiz' Project from a while back. The most notable differences are the tkinter UI, and the custom data from the Open Trivia Database.