Skip to content

Commit dafb27f

Browse files
Merge pull request #2946 from prashantgohel321/add-quizzler
Quizzler Project Using Tkinter and Trivia DB API
2 parents 9f61a99 + d622f62 commit dafb27f

File tree

11 files changed

+524
-0
lines changed

11 files changed

+524
-0
lines changed
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
# 🧠 Quizzler - Python-Based Quiz Application
2+
3+
## 📌 Overview
4+
5+
**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.
6+
7+
---
8+
9+
## 🎯 Objective
10+
11+
The primary goal of Quizzler is to:
12+
- Provide a user-friendly quiz experience.
13+
- Integrate with the Open Trivia DB API for dynamic question fetching.
14+
- Showcase modular and scalable code architecture using Python.
15+
16+
---
17+
18+
## Screenshots
19+
20+
### Initial Screen and result
21+
<table>
22+
<tr>
23+
<td><img src="./screenshots/s1.png" width="420px" height="250px" alt="Login Page"/></td>
24+
<td><img src="./screenshots/s4.png" width="420px" height="250px" alt="Register Page"/></td>
25+
</tr>
26+
</table>
27+
28+
### Response to wrong or correct answer
29+
<table>
30+
<tr>
31+
<td><img src="./screenshots/s2.png" width="420px" height="250px" alt="Profile Page"/></td>
32+
<td><img src="./screenshots/s3.png" width="420px" height="250px" alt="Home Page"/></td>
33+
</tr>
34+
</table>
35+
36+
---
37+
## 🛠️ Tech Stack
38+
39+
| Component | Technology |
40+
|------------------|---------------------|
41+
| Language | Python |
42+
| GUI Framework | Tkinter |
43+
| Data Source | Open Trivia DB API |
44+
| Architecture | Object-Oriented |
45+
46+
---
47+
48+
## 🧩 Project Structure
49+
50+
<pre>
51+
quizzler/
52+
53+
├── main.py # Main file to run the application
54+
├── ui.py # Handles the GUI logic with Tkinter
55+
├── quiz_brain.py # Core logic for question handling
56+
├── data.py # Module for API integration
57+
└── README.md # Documentation
58+
</pre>
59+
60+
61+
- `main.py`: Initializes the quiz and GUI components.
62+
- `ui.py`: Manages GUI rendering and button interactions.
63+
- `quiz_brain.py`: Controls quiz logic, answer checking, and scorekeeping.
64+
- `data.py`: Fetches quiz questions from the Open Trivia DB API.
65+
66+
---
67+
68+
## 🔌 API Integration
69+
70+
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.
71+
72+
Example API endpoint:
73+
> https://opentdb.com/api.php?amount=10&type=boolean
74+
75+
- You can adjust amount if you want more or less questions. And type also.
76+
77+
---
78+
79+
## 💻 How to Run
80+
81+
### ✅ Prerequisites
82+
83+
- Python 3.x installed on your machine
84+
- `requests` library (install via pip)
85+
86+
### 🧪 Installation Steps
87+
88+
```bash
89+
git clone https://github.com/prashantgohel321/Quizzler-Python.git
90+
cd quizzler
91+
pip install requests
92+
```
93+
94+
### Execution
95+
> python main.py
96+
97+
### Features
98+
- Clean and responsive UI with score tracking
99+
- Instant feedback with visual cues (color-based)
100+
- Real-time data fetching using API
101+
- Modular code architecture for scalability
102+
103+
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
2+
'''
3+
This file is responsible for fetching quiz questions from the Open Trivia Database API.
4+
'''
5+
6+
import requests
7+
8+
parameters = {
9+
"amount": 10,
10+
"type": "multiple",
11+
"category": 18
12+
}
13+
14+
error_message = ""
15+
16+
try:
17+
response = requests.get(url="https://opentdb.com/api.php", params=parameters, timeout=10)
18+
response.raise_for_status() # Raise an exception for HTTP errors
19+
question_data = response.json()["results"]
20+
print("Questions loaded successfully from the API.")
21+
except requests.exceptions.ConnectionError:
22+
error_message = "Network connection is poor. Please check your internet connection."
23+
question_data = []
24+
except requests.exceptions.Timeout:
25+
error_message = "Request timed out. Internet speed might be too slow."
26+
question_data = []
27+
except requests.exceptions.RequestException as e:
28+
error_message = f"An error occurred: {e}"
29+
question_data = []
Lines changed: 191 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,191 @@
1+
question_data = [
2+
{
3+
"question": "What is one of the main impacts of progress in hardware technologies on software?",
4+
"correct_answer": "Need for more sophisticated programs",
5+
"incorrect_answers": [
6+
"Increase in hardware prices",
7+
"Decrease in computational power",
8+
"Less complex problems for software engineers"
9+
]
10+
},
11+
{
12+
"question": "How have software engineers coped with the challenges of increasing computational capabilities?",
13+
"correct_answer": "By innovating and building on past experiences",
14+
"incorrect_answers": [
15+
"By reducing programming efforts",
16+
"By simplifying programming languages",
17+
"By avoiding large and complex problems"
18+
]
19+
},
20+
{
21+
"question": "Which of the following is a definition of software engineering according to IEEE?",
22+
"correct_answer": "The application of systematic, disciplined, quantifiable approach to software development, operation, and maintenance",
23+
"incorrect_answers": [
24+
"The art of writing computer programs",
25+
"An engineering approach to developing software",
26+
"A collection of unorganized programming techniques"
27+
]
28+
},
29+
{
30+
"question": "Why is software engineering similar to other engineering disciplines?",
31+
"correct_answer": "It uses well-understood and well-documented principles",
32+
"incorrect_answers": [
33+
"It makes use of subjective judgement and ill understood principles",
34+
"It often avoids conflicting goals",
35+
"It relies solely on qualitative attributes"
36+
]
37+
},
38+
{
39+
"question": "Which statement supports the idea that software engineering is not just an art?",
40+
"correct_answer": "It organizes experiences and provides theoretical bases to experimental observations",
41+
"incorrect_answers": [
42+
"It makes subjective judgement based on qualitative attributes",
43+
"It avoids systematic and disciplined approaches",
44+
"It does not require tradeoffs in problem solving"
45+
]
46+
},
47+
{
48+
"question": "How have software engineering principles evolved over the last sixty years?",
49+
"correct_answer": "From an art form to an engineering discipline",
50+
"incorrect_answers": [
51+
"From a science to an art form",
52+
"From a craft to an art form",
53+
"From an engineering discipline to a craft"
54+
]
55+
},
56+
{
57+
"question": "Which programming style is characterized by quickly developing a program without any specification, plan, or design?",
58+
"correct_answer": "Build and fix",
59+
"incorrect_answers": [
60+
"Exploratory",
61+
"Code and fix",
62+
"Ad hoc"
63+
]
64+
},
65+
{
66+
"question": "According to the text, what has been a symptom of the present software crisis?",
67+
"correct_answer": "Increasing software costs compared to hardware",
68+
"incorrect_answers": [
69+
"Decrease in software development costs",
70+
"Software products becoming easier to alter and debug",
71+
"Software products being delivered on time"
72+
]
73+
},
74+
{
75+
"question": "What is one of the main benefits of adopting software engineering techniques according to the text?",
76+
"correct_answer": "Developing high quality software cost effectively and timely",
77+
"incorrect_answers": [
78+
"Increasing hardware costs",
79+
"Avoiding the use of scientific principles",
80+
"Making software development more subjective"
81+
]
82+
},
83+
{
84+
"question": "What is a key characteristic of toy software?",
85+
"correct_answer": "Lack good user interface and proper documentation",
86+
"incorrect_answers": [
87+
"Developed by a team of professionals",
88+
"Large in size and highly complex",
89+
"Thoroughly tested and maintained"
90+
]
91+
}
92+
# {
93+
# "question": "What differentiates professional software from toy software?",
94+
# "correct_answer": "Professional software is systematically designed, carefully implemented, and thoroughly tested",
95+
# "incorrect_answers": [
96+
# "Professional software is usually developed by a single individual",
97+
# "Professional software lacks supporting documents",
98+
# "Professional software is used by a single user"
99+
# ]
100+
# },
101+
# {
102+
# "question": "What is a key feature of software services projects?",
103+
# "correct_answer": "They often involve the development of customized software",
104+
# "incorrect_answers": [
105+
# "They are always largescale projects",
106+
# "They involve the development of off-the-shelf software",
107+
# "They are never outsourced to other companies"
108+
# ]
109+
# },
110+
# {
111+
# "question": "Why might a company choose to outsource part of its software development work?",
112+
# "correct_answer": "To develop some parts cost effectively or to use external expertise",
113+
# "incorrect_answers": [
114+
# "To ensure all development work is done internally",
115+
# "Because it has more expertise than the outsourcing company",
116+
# "To avoid completing the project on time"
117+
# ]
118+
# },
119+
# {
120+
# "question": "What type of software is typically developed in a short time frame and at a low cost?",
121+
# "correct_answer": "Toy software",
122+
# "incorrect_answers": [
123+
# "Generic software products",
124+
# "Customized software",
125+
# "Professional software"
126+
# ]
127+
# },
128+
# {
129+
# "question": "What has been a traditional focus of Indian software companies?",
130+
# "correct_answer": "Executing software services projects",
131+
# "incorrect_answers": [
132+
# "Developing largescale generic software products",
133+
# "Avoiding any type of software development",
134+
# "Developing only toy software"
135+
# ]
136+
# },
137+
# {
138+
# "question": "What is the primary characteristic of the exploratory style of software development?",
139+
# "correct_answer": "Complete freedom for the programmer to choose development activities",
140+
# "incorrect_answers": [
141+
# "Strict adherence to development rules and guidelines",
142+
# "Development of software based on detailed specifications",
143+
# "Use of structured and well-documented procedures"
144+
# ]
145+
# },
146+
# {
147+
# "question": "What typically initiates the coding process in the exploratory development style?",
148+
# "correct_answer": "Initial customer briefing about requirements",
149+
# "incorrect_answers": [
150+
# "Completion of a detailed design document",
151+
# "Formal approval from a project manager",
152+
# "Completion of a feasibility study"
153+
# ]
154+
# },
155+
# {
156+
# "question": "What is a major limitation of the exploratory development style for large sized software projects?",
157+
# "correct_answer": "Development time and effort grow exponentially with problem size",
158+
# "incorrect_answers": [
159+
# "Requires a large team of developers",
160+
# "Results in highly structured and high quality code",
161+
# "Easily allows for concurrent work among multiple developers"
162+
# ]
163+
# },
164+
# {
165+
# "question": "What difficulty arises when using the exploratory style in a team development environment?",
166+
# "correct_answer": "Difficulty in partitioning work among developers due to lack of proper design and documentation",
167+
# "incorrect_answers": [
168+
# "Easy partitioning of work among developers",
169+
# "Development work is based on a detailed design",
170+
# "Use of structured and well documented code"
171+
# ]
172+
# },
173+
# {
174+
# "question": "In what scenario can the exploratory development style be successful?",
175+
# "correct_answer": "Developing very small programs",
176+
# "incorrect_answers": [
177+
# "Developing largescale enterprise software",
178+
# "Implementing critical safety systems",
179+
# "Managing large, distributed teams"
180+
# ]
181+
# },
182+
# {
183+
# "question": "What was the primary programming style used in the 1950s?",
184+
# "correct_answer": "Build and fix (exploratory programming) style",
185+
# "incorrect_answers": [
186+
# "Object-oriented programming",
187+
# "Control flow-based design",
188+
# "Data flow-oriented design"
189+
# ]
190+
# }
191+
]
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
2+
"""This file processes the fetched questions and prepares them for use in the quiz."""
3+
4+
from question_model import Question
5+
from data_dynamic import question_data
6+
from quiz_brain import QuizBrain
7+
from ui import QuizInterface
8+
9+
# question_bank = []
10+
# question_text = question["question"]
11+
# question_answer = question["correct_answer"]
12+
# question_options = question["incorrect_answers"] + [question["correct_answer"]]
13+
# new_question = Question(question_text, question_answer, question_options)
14+
# question_bank.append(new_question)
15+
16+
# list comprehension
17+
question_bank = [
18+
Question(
19+
question["question"],
20+
question["correct_answer"],
21+
question["incorrect_answers"] + [question["correct_answer"]]
22+
)
23+
for question in question_data
24+
]
25+
26+
quiz = QuizBrain(question_bank)
27+
quiz_ui = QuizInterface(quiz)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class Question:
2+
def __init__(self, q_text, q_answer, q_options):
3+
self.text = q_text
4+
self.answer = q_answer
5+
self.options = q_options
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
2+
"""This file contains the logic that drives the quiz game, including managing the current question, checking answers, and tracking the score."""
3+
4+
import html
5+
6+
class QuizBrain:
7+
def __init__(self, q_list):
8+
self.question_number = 0
9+
self.score = 0
10+
self.question_list = q_list
11+
self.current_question = None
12+
13+
def still_has_questions(self):
14+
return self.question_number < len(self.question_list)
15+
16+
def next_question(self):
17+
self.current_question = self.question_list[self.question_number]
18+
self.question_number += 1
19+
q_text = html.unescape(self.current_question.text)
20+
return f"Q.{self.question_number}: {q_text}"
21+
22+
def check_answer(self, user_answer):
23+
correct_answer = self.current_question.answer
24+
return user_answer.lower() == correct_answer.lower()
51.7 KB
Loading
50 KB
Loading
52.1 KB
Loading
58.8 KB
Loading

0 commit comments

Comments
 (0)