Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/anlbora/quizletgame_api
This is a desktop application built using Python and PyQt5 that quizzes users on a variety of topics. The questions are fetched dynamically from an online trivia API, and the game supports both true/false and multiple-choice questions.
https://github.com/anlbora/quizletgame_api
api game pyqt5 python quizlet quizlet-api
Last synced: about 2 months ago
JSON representation
This is a desktop application built using Python and PyQt5 that quizzes users on a variety of topics. The questions are fetched dynamically from an online trivia API, and the game supports both true/false and multiple-choice questions.
- Host: GitHub
- URL: https://github.com/anlbora/quizletgame_api
- Owner: anlbora
- License: mit
- Created: 2024-06-21T19:48:00.000Z (7 months ago)
- Default Branch: main
- Last Pushed: 2024-06-21T20:01:28.000Z (7 months ago)
- Last Synced: 2024-06-23T11:54:42.947Z (7 months ago)
- Topics: api, game, pyqt5, python, quizlet, quizlet-api
- Language: Python
- Homepage:
- Size: 33.2 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Quizlet Game Application
Welcome to the Quizlet Game Application! This is a desktop application built using Python and PyQt5 that quizzes users on a variety of topics. The questions are fetched dynamically from an online trivia API, and the game supports both true/false and multiple-choice questions.
## Table of Contents
- [Features](#features)
- [Usage](#usage)
- [Application Overview](#application-overview)
- [Code Structure](#code-structure)
- [Main Window](#main-window)
- [Question Handling](#question-handling)
- [Quiz Logic](#quiz-logic)
- [API Integration](#api-integration)## Features
- **Dynamic Question Loading**: Fetches questions from the Open Trivia Database (OpenTDB).
![1](https://github.com/anlbora/QuizletGame_Api/assets/100442507/fb017413-6653-47bc-9d83-36a1a55d8546)
- **Multiple Question Types**: Supports both true/false and multiple-choice questions.
![3](https://github.com/anlbora/QuizletGame_Api/assets/100442507/642f5a4a-1f7c-4f2e-8685-0be61d1d26d9)
- **User Feedback**: Provides immediate feedback on whether the answer is correct or wrong.![2](https://github.com/anlbora/QuizletGame_Api/assets/100442507/25df25e4-ec47-46b4-a6ed-7db74726002e)
![4](https://github.com/anlbora/QuizletGame_Api/assets/100442507/1c708588-41d9-4c22-88ac-f07fd2a11fb6)
![6](https://github.com/anlbora/QuizletGame_Api/assets/100442507/20ef8778-60cd-41be-9330-ffadd4db39cb)
- **Score Tracking**: Keeps track of the user's score throughout the quiz.
- **Responsive Design**: Adjusts font sizes to ensure readability across different screen sizes.![5](https://github.com/anlbora/QuizletGame_Api/assets/100442507/046fa456-8c40-4326-98b7-686aa2f6bfef)
## Usage
Once the application is running, you will be presented with a series of trivia questions. Depending on the type of question, you can either:
- **Click the True/False buttons** for true/false questions.
- **Click one of the option buttons** for multiple-choice questions.Your score will be updated based on your answers, and feedback will be provided immediately after each question. The game continues until there are no more questions left.
## Application Overview
### User Interface
The application's UI is built using PyQt5, providing a responsive and visually appealing design. Key components include:
- **Question Label**: Displays the current question.
- **Option Buttons**: For multiple-choice questions, four buttons are displayed for each possible answer.
- **True/False Buttons**: For true/false questions.
- **Score Label**: Displays the user's current score.### Game Flow
1. **Fetch Questions**: Questions are fetched from the OpenTDB API when the game starts.
2. **Display Question**: The current question is displayed along with the corresponding answer options.
3. **User Input**: The user selects an answer.
4. **Provide Feedback**: Immediate feedback is given, indicating if the answer was correct or wrong.
5. **Update Score**: The user's score is updated based on their answer.
6. **Next Question**: The next question is loaded, and the process repeats until all questions are answered.## Code Structure
### Main Window (`Main` Class)
This class initializes the main window and manages the overall game logic. Key methods include:
- `__init__`: Sets up the UI and initializes the question bank and quiz logic.
- `load_question`: Loads and displays the next question, adjusting the UI based on the question type.
- `give_feedback`: Provides feedback based on the user's answer and updates the score.
- `adjust_label_font_size`: Dynamically adjusts the font size of the question label to ensure it fits the available space.### Question Handling
Questions are fetched from the OpenTDB API and formatted appropriately for display. The `format_question_text` method handles the unescaping of HTML entities and formats the options for multiple-choice questions.
### Quiz Logic (`QuizBrain` Class)
Manages the state of the quiz, including the current question and the user's score. Key methods include:
- `next_question`: Retrieves the next question in the sequence.
- `check_answer`: Validates the user's answer against the correct answer for the current question.## API Integration
The application fetches questions from the [Open Trivia Database (OpenTDB)](https://opentdb.com/), an open-source API that provides trivia questions across various categories. The API request is made in the following way:
```python
url_base = "https://opentdb.com/api.php?"
amount = "10"
response = requests.get(f"{url_base}amount={amount}")
data = response.json()
question_data = data["results"]
```The questions are then processed and used throughout the game.