Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions Quizzler_App/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Quizzler App

A small True/False quiz GUI built with Python. The app fetches questions
from the Open Trivia Database (OpenTDB) and presents them in a simple
Tkinter interface with True/False image buttons and score tracking.

**Features**
- Fetches 10 boolean (True/False) questions from OpenTDB
- Simple GUI using `tkinter` with image buttons (`images/true.png`, `images/false.png`)
- Score tracking and immediate feedback (green/red) between questions

**Requirements**
- Python 3.7 or newer
- `requests` package (for fetching questions)
- Internet connection to fetch live questions from OpenTDB
- `tkinter` (normally included with standard Python installs)

**Install**
1. (Optional) Create and activate a virtual environment:

```bash
python -m venv venv
# Windows
venv\Scripts\activate
# macOS / Linux
source venv/bin/activate
```

2. Install dependencies:

```bash
pip install requests
```

**Run**
- Open a terminal in the project folder (Quizzler_App) and run:

```bash
python main.py
```

Note: Run from the `Quizzler_App` folder so the `images/` paths load correctly.

**Project files**
- `main.py` — Entry point. Builds question objects, starts the quiz UI.
- `ui.py` — Tkinter-based user interface and mainloop.
- `quiz_brain.py` — Quiz logic: question flow, scoring, and answer checking.
- `question_model.py` — Simple `Question` model (`text` and `answer`).
- `data.py` — Fetches question data from OpenTDB using `requests` (see note below).
- `images/` — Contains `true.png` and `false.png` used as button images.

**Notes & customization**
- `data.py` currently fetches questions from OpenTDB at runtime. If you
want to run the app offline, replace the request block and use the
static `question_data` list (there is an example commented out in `data.py`).
- If the image buttons do not display, ensure the `images` folder and
files are present and that you run `python main.py` from the project folder.

**Contributing / Troubleshooting**
- If you see network errors, check your internet connection and API availability.
- Ensure `requests` is installed in the active Python environment.

Have fun quizzing! 🎉
Binary file added Quizzler_App/__pycache__/data.cpython-311.pyc
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added Quizzler_App/__pycache__/ui.cpython-311.pyc
Binary file not shown.
129 changes: 129 additions & 0 deletions Quizzler_App/data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
import requests

parameters = {
"amount":10,
"type":"boolean"
}

response = requests.get(url="https://opentdb.com/api.php?",params=parameters)
response.raise_for_status()
data = response.json()
question_data = data["results"]
















# question_data = [
# {
# "category": "Science: Computers",
# "type": "boolean",
# "difficulty": "medium",
# "question": "The HTML5 standard was published in 2014.",
# "correct_answer": "True",
# "incorrect_answers": [
# "False"
# ]
# },
# {
# "category": "Science: Computers",
# "type": "boolean",
# "difficulty": "medium",
# "question": "The first computer bug was formed by faulty wires.",
# "correct_answer": "False",
# "incorrect_answers": [
# "True"
# ]
# },
# {
# "category": "Science: Computers",
# "type": "boolean",
# "difficulty": "medium",
# "question": "FLAC stands for 'Free Lossless Audio Condenser'.",
# "correct_answer": "False",
# "incorrect_answers": [
# "True"
# ]
# },
# {
# "category": "Science: Computers",
# "type": "boolean",
# "difficulty": "medium",
# "question": "All program codes have to be compiled into an executable file in order to be run. This file can then be executed on any machine.",
# "correct_answer": "False",
# "incorrect_answers": [
# "True"
# ]
# },
# {
# "category": "Science: Computers",
# "type": "boolean",
# "difficulty": "easy",
# "question": "Linus Torvalds created Linux and Git.",
# "correct_answer": "True",
# "incorrect_answers": [
# "False"
# ]
# },
# {
# "category": "Science: Computers",
# "type": "boolean",
# "difficulty": "easy",
# "question": "The programming language 'Python' is based off a modified version of 'JavaScript'",
# "correct_answer": "False",
# "incorrect_answers": [
# "True"
# ]
# },
# {
# "category": "Science: Computers",
# "type": "boolean",
# "difficulty": "medium",
# "question": "AMD created the first consumer 64-bit processor.",
# "correct_answer": "True",
# "incorrect_answers": [
# "False"
# ]
# },
# {
# "category": "Science: Computers",
# "type": "boolean",
# "difficulty": "easy",
# "question": "'HTML' stands for Hypertext Markup Language.",
# "correct_answer": "True",
# "incorrect_answers": [
# "False"
# ]
# },
# {
# "category": "Science: Computers",
# "type": "boolean",
# "difficulty": "easy",
# "question": "In most programming languages, the operator ++ is equivalent to the statement '+= 1'.",
# "correct_answer": "True",
# "incorrect_answers": [
# "False"
# ]
# },
# {
# "category": "Science: Computers",
# "type": "boolean",
# "difficulty": "hard",
# "question": "The IBM PC used an Intel 8008 microprocessor clocked at 4.77 MHz and 8 kilobytes of memory.",
# "correct_answer": "False",
# "incorrect_answers": [
# "True"
# ]
# }
# ]
Binary file added Quizzler_App/images/false.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Quizzler_App/images/true.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions Quizzler_App/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from question_model import Question
from data import question_data
from quiz_brain import QuizBrain
from ui import QuizInterface

question_bank = []
for question in question_data:
question_text = question["question"]
question_answer = question["correct_answer"]
new_question = Question(question_text, question_answer)
question_bank.append(new_question)


quiz = QuizBrain(question_bank)
quiz_ui = QuizInterface(quiz)

# while quiz.still_has_questions():
# quiz.next_question()

print("You've completed the quiz")
print(f"Your final score was: {quiz.score}/{quiz.question_number}")
5 changes: 5 additions & 0 deletions Quizzler_App/question_model.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class Question:

def __init__(self, q_text, q_answer):
self.text = q_text
self.answer = q_answer
32 changes: 32 additions & 0 deletions Quizzler_App/quiz_brain.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import html




class QuizBrain:

def __init__(self, q_list):
self.question_number = 0
self.score = 0
self.question_list = q_list
self.current_question = None

def still_has_questions(self):
return self.question_number < len(self.question_list)

def next_question(self):
self.current_question = self.question_list[self.question_number]
self.question_number += 1
q_text = html.unescape(self.current_question.text)
return f"Q.{self.question_number}: {q_text}"
# user_answer = input(f"Q.{self.question_number}: {q_text} (True/False): ")
# self.check_answer(user_answer)

def check_answer(self, user_answer):
correct_answer = self.current_question.answer
if user_answer.lower() == correct_answer.lower():
self.score += 1
return True
else:
return False

65 changes: 65 additions & 0 deletions Quizzler_App/ui.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
from tkinter import *
from quiz_brain import QuizBrain

THEME_COLOR = "#375362"


class QuizInterface :
def __init__(self,quiz_brain: QuizBrain):
self.quiz = quiz_brain
self.window = Tk()
self.window.title("Quizzler")
self.window.config(bg=THEME_COLOR,padx=20,pady=20)

self.score_label = Label(text="Score:0", fg="white",bg=THEME_COLOR)
self.score_label.grid(row=0,column=1)

self.canvas = Canvas(width=300,height=250,bg="white")
self.question_text = self.canvas.create_text(
150,
125,
width=280,
text="Some Question Text",
fill=THEME_COLOR,
font=("Arial",20,"italic")
)
self.canvas.grid(row=1,column=0,columnspan=2,pady=50)

true_button_img = PhotoImage(file="images/true.png")
self.true_button = Button(image=true_button_img,command=self.true_pressed)
self.true_button.grid(row=2,column=0)

false_button_img = PhotoImage(file="images/false.png")
self.false_button = Button(image=false_button_img,command=self.false_pressed)
self.false_button.grid(row=2,column=1)

self.get_next_question()

self.window.mainloop()

def get_next_question(self):
self.canvas.config(bg="white")
if self.quiz.still_has_questions():
self.score_label.config(text=f"Score:{self.quiz.score}")
q_text = self.quiz.next_question()
self.canvas.itemconfig(self.question_text,text=q_text)
else :
self.canvas.itemconfig(self.question_text,text="You've reached thee end of the quiz.")
self.true_button.config(state="disabled")
self.false_button.config(state="disabled")
def true_pressed(self):
is_right=self.quiz.check_answer("True")
self.give_feedback(is_right)

def false_pressed(self):
is_right=self.quiz.check_answer("False")
self.give_feedback(is_right)

def give_feedback(self,is_right):
if is_right:
self.canvas.config(bg="green")
else:
self.canvas.config(bg="red")
self.window.after(1000,func=self.get_next_question)