Skip to content
Merged
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
103 changes: 103 additions & 0 deletions Quizzler Using Tkinter and Trivia DB API/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
# 🧠 Quizzler - Python-Based Quiz Application

## 📌 Overview

**Quizzler** is a Python-based GUI quiz application that fetches trivia questions from an online API and challenges the user with a series of True/False questions. Built using **Tkinter**, the app demonstrates effective use of object-oriented programming, API integration, and interactive UI design in Python.

---

## 🎯 Objective

The primary goal of Quizzler is to:
- Provide a user-friendly quiz experience.
- Integrate with the Open Trivia DB API for dynamic question fetching.
- Showcase modular and scalable code architecture using Python.

---

## Screenshots

### Initial Screen and result
<table>
<tr>
<td><img src="./screenshots/s1.png" width="420px" height="250px" alt="Login Page"/></td>
<td><img src="./screenshots/s4.png" width="420px" height="250px" alt="Register Page"/></td>
</tr>
</table>

### Response to wrong or correct answer
<table>
<tr>
<td><img src="./screenshots/s2.png" width="420px" height="250px" alt="Profile Page"/></td>
<td><img src="./screenshots/s3.png" width="420px" height="250px" alt="Home Page"/></td>
</tr>
</table>

---
## 🛠️ Tech Stack

| Component | Technology |
|------------------|---------------------|
| Language | Python |
| GUI Framework | Tkinter |
| Data Source | Open Trivia DB API |
| Architecture | Object-Oriented |

---

## 🧩 Project Structure

<pre>
quizzler/
├── main.py # Main file to run the application
├── ui.py # Handles the GUI logic with Tkinter
├── quiz_brain.py # Core logic for question handling
├── data.py # Module for API integration
└── README.md # Documentation
</pre>


- `main.py`: Initializes the quiz and GUI components.
- `ui.py`: Manages GUI rendering and button interactions.
- `quiz_brain.py`: Controls quiz logic, answer checking, and scorekeeping.
- `data.py`: Fetches quiz questions from the Open Trivia DB API.

---

## 🔌 API Integration

Questions are fetched using a GET request from the [Open Trivia Database API](https://opentdb.com/api_config.php). The app dynamically parses the JSON response and formats it for display.

Example API endpoint:
> https://opentdb.com/api.php?amount=10&type=boolean

- You can adjust amount if you want more or less questions. And type also.

---

## 💻 How to Run

### ✅ Prerequisites

- Python 3.x installed on your machine
- `requests` library (install via pip)

### 🧪 Installation Steps

```bash
git clone https://github.com/prashantgohel321/Quizzler-Python.git
cd quizzler
pip install requests
```

### Execution
> python main.py

### Features
- Clean and responsive UI with score tracking
- Instant feedback with visual cues (color-based)
- Real-time data fetching using API
- Modular code architecture for scalability


29 changes: 29 additions & 0 deletions Quizzler Using Tkinter and Trivia DB API/data_dynamic.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@

'''
This file is responsible for fetching quiz questions from the Open Trivia Database API.
'''

import requests

parameters = {
"amount": 10,
"type": "multiple",
"category": 18
}

error_message = ""

try:
response = requests.get(url="https://opentdb.com/api.php", params=parameters, timeout=10)
response.raise_for_status() # Raise an exception for HTTP errors
question_data = response.json()["results"]
print("Questions loaded successfully from the API.")
except requests.exceptions.ConnectionError:
error_message = "Network connection is poor. Please check your internet connection."
question_data = []
except requests.exceptions.Timeout:
error_message = "Request timed out. Internet speed might be too slow."
question_data = []
except requests.exceptions.RequestException as e:
error_message = f"An error occurred: {e}"
question_data = []
191 changes: 191 additions & 0 deletions Quizzler Using Tkinter and Trivia DB API/data_static.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
question_data = [
{
"question": "What is one of the main impacts of progress in hardware technologies on software?",
"correct_answer": "Need for more sophisticated programs",
"incorrect_answers": [
"Increase in hardware prices",
"Decrease in computational power",
"Less complex problems for software engineers"
]
},
{
"question": "How have software engineers coped with the challenges of increasing computational capabilities?",
"correct_answer": "By innovating and building on past experiences",
"incorrect_answers": [
"By reducing programming efforts",
"By simplifying programming languages",
"By avoiding large and complex problems"
]
},
{
"question": "Which of the following is a definition of software engineering according to IEEE?",
"correct_answer": "The application of systematic, disciplined, quantifiable approach to software development, operation, and maintenance",
"incorrect_answers": [
"The art of writing computer programs",
"An engineering approach to developing software",
"A collection of unorganized programming techniques"
]
},
{
"question": "Why is software engineering similar to other engineering disciplines?",
"correct_answer": "It uses well-understood and well-documented principles",
"incorrect_answers": [
"It makes use of subjective judgement and ill understood principles",
"It often avoids conflicting goals",
"It relies solely on qualitative attributes"
]
},
{
"question": "Which statement supports the idea that software engineering is not just an art?",
"correct_answer": "It organizes experiences and provides theoretical bases to experimental observations",
"incorrect_answers": [
"It makes subjective judgement based on qualitative attributes",
"It avoids systematic and disciplined approaches",
"It does not require tradeoffs in problem solving"
]
},
{
"question": "How have software engineering principles evolved over the last sixty years?",
"correct_answer": "From an art form to an engineering discipline",
"incorrect_answers": [
"From a science to an art form",
"From a craft to an art form",
"From an engineering discipline to a craft"
]
},
{
"question": "Which programming style is characterized by quickly developing a program without any specification, plan, or design?",
"correct_answer": "Build and fix",
"incorrect_answers": [
"Exploratory",
"Code and fix",
"Ad hoc"
]
},
{
"question": "According to the text, what has been a symptom of the present software crisis?",
"correct_answer": "Increasing software costs compared to hardware",
"incorrect_answers": [
"Decrease in software development costs",
"Software products becoming easier to alter and debug",
"Software products being delivered on time"
]
},
{
"question": "What is one of the main benefits of adopting software engineering techniques according to the text?",
"correct_answer": "Developing high quality software cost effectively and timely",
"incorrect_answers": [
"Increasing hardware costs",
"Avoiding the use of scientific principles",
"Making software development more subjective"
]
},
{
"question": "What is a key characteristic of toy software?",
"correct_answer": "Lack good user interface and proper documentation",
"incorrect_answers": [
"Developed by a team of professionals",
"Large in size and highly complex",
"Thoroughly tested and maintained"
]
}
# {
# "question": "What differentiates professional software from toy software?",
# "correct_answer": "Professional software is systematically designed, carefully implemented, and thoroughly tested",
# "incorrect_answers": [
# "Professional software is usually developed by a single individual",
# "Professional software lacks supporting documents",
# "Professional software is used by a single user"
# ]
# },
# {
# "question": "What is a key feature of software services projects?",
# "correct_answer": "They often involve the development of customized software",
# "incorrect_answers": [
# "They are always largescale projects",
# "They involve the development of off-the-shelf software",
# "They are never outsourced to other companies"
# ]
# },
# {
# "question": "Why might a company choose to outsource part of its software development work?",
# "correct_answer": "To develop some parts cost effectively or to use external expertise",
# "incorrect_answers": [
# "To ensure all development work is done internally",
# "Because it has more expertise than the outsourcing company",
# "To avoid completing the project on time"
# ]
# },
# {
# "question": "What type of software is typically developed in a short time frame and at a low cost?",
# "correct_answer": "Toy software",
# "incorrect_answers": [
# "Generic software products",
# "Customized software",
# "Professional software"
# ]
# },
# {
# "question": "What has been a traditional focus of Indian software companies?",
# "correct_answer": "Executing software services projects",
# "incorrect_answers": [
# "Developing largescale generic software products",
# "Avoiding any type of software development",
# "Developing only toy software"
# ]
# },
# {
# "question": "What is the primary characteristic of the exploratory style of software development?",
# "correct_answer": "Complete freedom for the programmer to choose development activities",
# "incorrect_answers": [
# "Strict adherence to development rules and guidelines",
# "Development of software based on detailed specifications",
# "Use of structured and well-documented procedures"
# ]
# },
# {
# "question": "What typically initiates the coding process in the exploratory development style?",
# "correct_answer": "Initial customer briefing about requirements",
# "incorrect_answers": [
# "Completion of a detailed design document",
# "Formal approval from a project manager",
# "Completion of a feasibility study"
# ]
# },
# {
# "question": "What is a major limitation of the exploratory development style for large sized software projects?",
# "correct_answer": "Development time and effort grow exponentially with problem size",
# "incorrect_answers": [
# "Requires a large team of developers",
# "Results in highly structured and high quality code",
# "Easily allows for concurrent work among multiple developers"
# ]
# },
# {
# "question": "What difficulty arises when using the exploratory style in a team development environment?",
# "correct_answer": "Difficulty in partitioning work among developers due to lack of proper design and documentation",
# "incorrect_answers": [
# "Easy partitioning of work among developers",
# "Development work is based on a detailed design",
# "Use of structured and well documented code"
# ]
# },
# {
# "question": "In what scenario can the exploratory development style be successful?",
# "correct_answer": "Developing very small programs",
# "incorrect_answers": [
# "Developing largescale enterprise software",
# "Implementing critical safety systems",
# "Managing large, distributed teams"
# ]
# },
# {
# "question": "What was the primary programming style used in the 1950s?",
# "correct_answer": "Build and fix (exploratory programming) style",
# "incorrect_answers": [
# "Object-oriented programming",
# "Control flow-based design",
# "Data flow-oriented design"
# ]
# }
]
27 changes: 27 additions & 0 deletions Quizzler Using Tkinter and Trivia DB API/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@

"""This file processes the fetched questions and prepares them for use in the quiz."""

from question_model import Question
from data_dynamic import question_data
from quiz_brain import QuizBrain
from ui import QuizInterface

# question_bank = []
# question_text = question["question"]
# question_answer = question["correct_answer"]
# question_options = question["incorrect_answers"] + [question["correct_answer"]]
# new_question = Question(question_text, question_answer, question_options)
# question_bank.append(new_question)

# list comprehension
question_bank = [
Question(
question["question"],
question["correct_answer"],
question["incorrect_answers"] + [question["correct_answer"]]
)
for question in question_data
]

quiz = QuizBrain(question_bank)
quiz_ui = QuizInterface(quiz)
5 changes: 5 additions & 0 deletions Quizzler Using Tkinter and Trivia DB API/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, q_options):
self.text = q_text
self.answer = q_answer
self.options = q_options
24 changes: 24 additions & 0 deletions Quizzler Using Tkinter and Trivia DB API/quiz_brain.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@

"""This file contains the logic that drives the quiz game, including managing the current question, checking answers, and tracking the score."""

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}"

def check_answer(self, user_answer):
correct_answer = self.current_question.answer
return user_answer.lower() == correct_answer.lower()
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading