Professional, minimal desktop quiz management application built with Flet (Python). This repository contains the UI and database bootstrap logic used to create and save quiz questions to a MySQL database.
Ensure your system has the following installed:
- Python 3.10+ (Download)
- pip (Python package manager - typically included with Python)
- git (for version control)
- virtualenv or venv Python virtual environment
git clone https://github.com/mihaiapostol14/FletQuizzGame.git
cd FletQuizzGameOn Linux/macOS:
python3 -m venv venv
source venv/bin/activateOn Windows:
python -m venv venv
venv\Scripts\activatepython -m pip install --upgrade pip
pip install -r requirements.txtcp config/.env.example .env
# then edit .env and set LOCALHOST, USER, PASSWORD, DATABASEStep 5: Initialize the database tables (this runs automatically on startup but you can run directly):
python database.pypython game.pyFletQuizzGame/
├─ assets/
│ ├─ icon/
│ │ └─ icon.ico (used by the desktop window)
│ └─ preview.png
├─ config/
│ ├─ .env.example
│ ├─ __init__.py
│ └─ load.py
├─ database.py
├─ game.py
├─ requirements.txt
└─ README.md
- 🧠 Create and save quiz questions from a simple, modern desktop UI (Flet)
- 💾 MySQL integration for persistent storage and table creation
- 🧩 Lightweight single-file UI (game.py) and database manager (database.py)
- ⚡ Quick bootstrap: create tables automatically when the app starts
- Frontend / Desktop UI: Flet (Python) — declarative UI toolkit that runs on desktop and web.
- Database: MySQL accessed via mysql-connector-python (DatabaseManager in
database.py). - Configuration: python-dotenv to load environment variables from
.env(seeconfig/load.py). - Runtime: CPython 3.8+ with dependencies listed in
requirements.txt.
Design notes: the UI is implemented in game.py (Flet Page + controls). The DatabaseManager encapsulates connection handling, query execution, and table creation.
Below are actionable findings from a code review of database.py and game.py.
- Logic issues
- The
questionstable schema expects option_a..option_d and correct_option, but the UI collects only two answers and a username. TheINSERTingame.pyinserts the username intocorrect_optionand writes "none" into option_c/option_d. This is a schema/design mismatch — define the data model or adapt the UI. - The
scorestable is created but never used by the application. Consider removing or implementing score persistence logic.
- Security
- Credentials are loaded from environment variables via
config/load.pywhich is good practice. Ensure.envis never committed to source control. - The database access uses parameterized queries (placeholders %s) which protects against SQL injection — good.
- Avoid printing raw exception text to UI dialogs in production (currently the DB exception is shown in an AlertDialog). Logging the exception server-side and showing a friendly message to users is recommended.
- Validate and normalize user input (e.g., max lengths) before saving to the DB. At present values can be arbitrarily long.
- Robustness and error handling
DatabaseManager.get_connection()returns None on error and caller code silently continues. Prefer raising descriptive exceptions or returning an explicit Result/raise to force the caller to handle failure.- When using
DatabaseManager.execute_query()ingame.py, failures are swallowed (print) — surface failures to the UI or log them and show a clean message. - The
config/load.pyuses generic names (USER) which can collide with OS environment variables. Use explicit names like DB_USER or MYSQL_USER to avoid confusion.
- PEP 8 / style
database.pyhas inconsistent indentation (file uses two-space indentation for class method bodies) — PEP 8 recommends 4 spaces per indentation level. Reformat to 4 spaces.- Add type hints to public methods (e.g., get_connection -> mysql.connector.MySQLConnection | None) and return types for clarity.
- Long SQL strings and multi-line blocks are fine but consider using textwrap.dedent for readability.
- Use a logger (logging module) instead of print statements.
- Recommended quick fixes (snippets)
- database.py: normalize indentation, add logging, and raise exceptions instead of returning None:
import logging
from mysql.connector import connect, Error
logger = logging.getLogger(__name__)
class DatabaseManager:
def get_connection(self) -> mysql.connector.MySQLConnection:
try:
conn = connect(**self.config)
return conn
except Error as exc:
logger.exception("MySQL connection failed")
raise- game.py: fix insert mapping (example given a model that stores
authorcolumn):
query = """
INSERT INTO questions (
question_text, option_a, option_b, option_c, option_d, correct_option
) VALUES (%s, %s, %s, %s, %s, %s)
"""
params = (question, ans_1, ans_2, 'N/A', 'N/A', 'A') # or correct_option chosen- Additional suggestions
- Add unit tests for DatabaseManager (using a test database or mocks).
- Add a LICENSE file and choose a license.
- Add a simple CI workflow (GitHub Actions) to run flake8/black and tests on push.
- Consider using SQLAlchemy for a cleaner ORM and migrations (Alembic) if the data model will grow.
This project is licensed under the MIT License - see the LICENSE file for details.
