And again, thank you! This is a good start for small tools to send a text field with a selection to a REST API in order to trigger specific actions - independently of a web browser.
*PyQt6 and Databases: Building a Todo App with QtSql* * *0:00** Introduction:* Following up on a popular request, this video demonstrates building a more advanced PyQt6 desktop application integrated with an SQL database. The app will allow users to manage a todo list. * *0:30** QtSql Module:* Introduction to PyQt6's QtSql module, which enables integration with SQL databases. Key classes discussed include `QSqlDatabase` for connections and `QSqlQuery` for executing queries. The pronunciation of PyQt (as "py-cute") is also clarified. * *1:38** Creating the Database:* An SQLite database named "todos.sqlite" is created. A "todos" table is created within the database with columns for ID (primary key), name (varchar), and completed (boolean). The VS Code SQLite extension is recommended for database visualization. * *3:13** Database Connection:* A Python function `open_connection` is defined to establish and close the database connection using `QSqlDatabase`. The function returns `True` if the connection is successful. The code is later moved to a separate `db.py` module for better organization. * *8:36** MainWindow:* A `MainWindow` class is created, inheriting from `QtWidgets.QMainWindow`. This class sets up the main application window, including the title and central widget. The `open_connection` function is called before creating the window to ensure data availability. * *11:48** Todo Form Widget:* A `TodoForm` widget is created in `create_todo.py`, inheriting from `QtWidgets.QWidget`. This widget contains input fields for the todo name (`QLineEdit`), a checkbox for completion status (`QCheckBox`), and a submit button (`QPushButton`). * *18:47** Todo Table Widget:* A `TodoTable` widget is created in `todo_table.py`, also inheriting from `QtWidgets.QWidget`. This widget uses a `QTableWidget` to display the todo items. Columns are set for "Todo Name" and "Completed?". * *21:58** Form Submission and Database Interaction:* The `submit_todo` method in `TodoForm` handles form submission. It retrieves user input, constructs an SQL insert query using `QSqlQuery.prepare` (to prevent SQL injection), binds the values, and executes the query. A success message (`QMessageBox`) is displayed upon successful insertion, and the input fields are cleared. A warning message is displayed if the user doesn't enter a todo name. * *27:19** Updating the Table on Submit:* A callback mechanism is implemented to update the `TodoTable` whenever a new todo is submitted. The `add_todo_to_list` method in `MainWindow` acts as an intermediary, calling the `add_todo_item` method of `TodoTable`. * *34:30** Populating the Table on Load:* The `get_todos` method in `TodoTable` is called within the `__init__` method to populate the table with existing database entries when the application starts. It fetches data using a select query and iterates through the results, adding each item to the `QTableWidget`. The `completed` status is converted from a boolean to "Completed" or "Pending" for display. I used gemini-1.5-pro-002 on rocketrecap dot com to summarize the transcript. Cost (if I didn't use the free tier): $0.04 Input tokens: 26654 Output tokens: 704
On Desktop app, you need to compile to exe and install before you can use. On Web (Online) Application, you only need the url (ip url too) which makes it easier. I have a working web app done with Python Django but I am considering converting it to a Desktop App.
And again, thank you! This is a good start for small tools to send a text field with a selection to a REST API in order to trigger specific actions - independently of a web browser.
Thanks! Hoping to do more soon.
Thank you for this. Question at which point do you close the database ?.
Thank you for video
Thanks for watching!
thank
Thanks a lot!
good thank
Thanks for watching!
*PyQt6 and Databases: Building a Todo App with QtSql*
* *0:00** Introduction:* Following up on a popular request, this video demonstrates building a more advanced PyQt6 desktop application integrated with an SQL database. The app will allow users to manage a todo list.
* *0:30** QtSql Module:* Introduction to PyQt6's QtSql module, which enables integration with SQL databases. Key classes discussed include `QSqlDatabase` for connections and `QSqlQuery` for executing queries. The pronunciation of PyQt (as "py-cute") is also clarified.
* *1:38** Creating the Database:* An SQLite database named "todos.sqlite" is created. A "todos" table is created within the database with columns for ID (primary key), name (varchar), and completed (boolean). The VS Code SQLite extension is recommended for database visualization.
* *3:13** Database Connection:* A Python function `open_connection` is defined to establish and close the database connection using `QSqlDatabase`. The function returns `True` if the connection is successful. The code is later moved to a separate `db.py` module for better organization.
* *8:36** MainWindow:* A `MainWindow` class is created, inheriting from `QtWidgets.QMainWindow`. This class sets up the main application window, including the title and central widget. The `open_connection` function is called before creating the window to ensure data availability.
* *11:48** Todo Form Widget:* A `TodoForm` widget is created in `create_todo.py`, inheriting from `QtWidgets.QWidget`. This widget contains input fields for the todo name (`QLineEdit`), a checkbox for completion status (`QCheckBox`), and a submit button (`QPushButton`).
* *18:47** Todo Table Widget:* A `TodoTable` widget is created in `todo_table.py`, also inheriting from `QtWidgets.QWidget`. This widget uses a `QTableWidget` to display the todo items. Columns are set for "Todo Name" and "Completed?".
* *21:58** Form Submission and Database Interaction:* The `submit_todo` method in `TodoForm` handles form submission. It retrieves user input, constructs an SQL insert query using `QSqlQuery.prepare` (to prevent SQL injection), binds the values, and executes the query. A success message (`QMessageBox`) is displayed upon successful insertion, and the input fields are cleared. A warning message is displayed if the user doesn't enter a todo name.
* *27:19** Updating the Table on Submit:* A callback mechanism is implemented to update the `TodoTable` whenever a new todo is submitted. The `add_todo_to_list` method in `MainWindow` acts as an intermediary, calling the `add_todo_item` method of `TodoTable`.
* *34:30** Populating the Table on Load:* The `get_todos` method in `TodoTable` is called within the `__init__` method to populate the table with existing database entries when the application starts. It fetches data using a select query and iterates through the results, adding each item to the `QTableWidget`. The `completed` status is converted from a boolean to "Completed" or "Pending" for display.
I used gemini-1.5-pro-002 on rocketrecap dot com to summarize the transcript.
Cost (if I didn't use the free tier): $0.04
Input tokens: 26654
Output tokens: 704
What are these day the incentive to make a desktop application versus a online application?
I would also be interested behind in the thought behind this!
On Desktop app, you need to compile to exe and install before you can use.
On Web (Online) Application, you only need the url (ip url too) which makes it easier.
I have a working web app done with Python Django but I am considering converting it to a Desktop App.
Well, a good reason could be that you dont want your data to be in a server elsewhere and want to process the data locally, independently.