diff --git a/Quizzler_App/README.md b/Quizzler_App/README.md new file mode 100644 index 0000000..e56d4f6 --- /dev/null +++ b/Quizzler_App/README.md @@ -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! 🎉 diff --git a/Quizzler_App/__pycache__/data.cpython-311.pyc b/Quizzler_App/__pycache__/data.cpython-311.pyc new file mode 100644 index 0000000..62242a0 Binary files /dev/null and b/Quizzler_App/__pycache__/data.cpython-311.pyc differ diff --git a/Quizzler_App/__pycache__/question_model.cpython-311.pyc b/Quizzler_App/__pycache__/question_model.cpython-311.pyc new file mode 100644 index 0000000..d60b694 Binary files /dev/null and b/Quizzler_App/__pycache__/question_model.cpython-311.pyc differ diff --git a/Quizzler_App/__pycache__/quiz_brain.cpython-311.pyc b/Quizzler_App/__pycache__/quiz_brain.cpython-311.pyc new file mode 100644 index 0000000..c6bc6cc Binary files /dev/null and b/Quizzler_App/__pycache__/quiz_brain.cpython-311.pyc differ diff --git a/Quizzler_App/__pycache__/ui.cpython-311.pyc b/Quizzler_App/__pycache__/ui.cpython-311.pyc new file mode 100644 index 0000000..f0b5c01 Binary files /dev/null and b/Quizzler_App/__pycache__/ui.cpython-311.pyc differ diff --git a/Quizzler_App/data.py b/Quizzler_App/data.py new file mode 100644 index 0000000..4cc7d68 --- /dev/null +++ b/Quizzler_App/data.py @@ -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" +# ] +# } +# ] diff --git a/Quizzler_App/images/false.png b/Quizzler_App/images/false.png new file mode 100644 index 0000000..904c76d Binary files /dev/null and b/Quizzler_App/images/false.png differ diff --git a/Quizzler_App/images/true.png b/Quizzler_App/images/true.png new file mode 100644 index 0000000..79ca9a3 Binary files /dev/null and b/Quizzler_App/images/true.png differ diff --git a/Quizzler_App/main.py b/Quizzler_App/main.py new file mode 100644 index 0000000..b60364c --- /dev/null +++ b/Quizzler_App/main.py @@ -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}") diff --git a/Quizzler_App/question_model.py b/Quizzler_App/question_model.py new file mode 100644 index 0000000..b3d63d3 --- /dev/null +++ b/Quizzler_App/question_model.py @@ -0,0 +1,5 @@ +class Question: + + def __init__(self, q_text, q_answer): + self.text = q_text + self.answer = q_answer diff --git a/Quizzler_App/quiz_brain.py b/Quizzler_App/quiz_brain.py new file mode 100644 index 0000000..f3d3a1b --- /dev/null +++ b/Quizzler_App/quiz_brain.py @@ -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 + diff --git a/Quizzler_App/ui.py b/Quizzler_App/ui.py new file mode 100644 index 0000000..0e54b3a --- /dev/null +++ b/Quizzler_App/ui.py @@ -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) + +