Python 3 PyQt5 Lineup for the day Muck Application Utilizing SQLite Data set GUI Work area Application I’m exceptionally intrigued to converse with you about this article. The explanation is that this article contains exceptionally fascinating data. How about we go to this article
Python 3 PyQt5 TODO List CRUD App Using SQLite Database GUI Desktop App
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'todo.ui'
#
# Created by: PyQt5 UI code generator 5.15.4
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again. Do not edit this file unless you know what you are doing.
from PyQt5 import QtCore, QtGui, QtWidgets
import sqlite3
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(500, 600)
icon = QtGui.QIcon()
icon.addPixmap(QtGui.QPixmap("to-do-list.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
MainWindow.setWindowIcon(icon)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.task_input = QtWidgets.QLineEdit(self.centralwidget)
self.task_input.setGeometry(QtCore.QRect(30, 370, 431, 25))
self.task_input.setObjectName("task_input")
self.date_input = QtWidgets.QLineEdit(self.centralwidget)
self.date_input.setGeometry(QtCore.QRect(30, 410, 201, 25))
self.date_input.setObjectName("date_input")
self.add_button = QtWidgets.QPushButton(self.centralwidget)
self.add_button.setGeometry(QtCore.QRect(70, 490, 91, 71))
self.add_button.setObjectName("add_button")
self.remove_button = QtWidgets.QPushButton(self.centralwidget)
self.remove_button.setGeometry(QtCore.QRect(330, 490, 91, 71))
self.remove_button.setObjectName("remove_button")
self.todo_list = QtWidgets.QTableWidget(self.centralwidget)
self.todo_list.setGeometry(QtCore.QRect(30, 30, 431, 311))
self.todo_list.setObjectName("todo_list")
self.info_label = QtWidgets.QLabel(self.centralwidget)
self.info_label.setGeometry(QtCore.QRect(150,570,200,20))
self.todo_list.setColumnCount(3)
MainWindow.setCentralWidget(self.centralwidget)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
self.add_button.clicked.connect(self.add_task)
self.remove_button.clicked.connect(self.remove_task)
self.connect_database()
def connect_database(self):
global db, db_cursor, tasks, dates, x , rows
db = sqlite3.connect("tasks.db")
db_cursor = db.cursor()
try:
db_cursor.execute("CREATE TABLE to_do (id INTEGER PRIMARY KEY AUTOINCREMENT,task text,date text)")
except:
pass
db_cursor.execute("SELECT * FROM to_do")
self.todo_list.clearContents()
self.todo_list.setRowCount(0)
data = db_cursor.fetchall()
#add tasks from database to the table
for r1 in range(len(data)):
item = data[r1]
item = list(item)
self.todo_list.insertRow(r1)
self.todo_list.setItem(r1, 0, QtWidgets.QTableWidgetItem(str(item[0])))
self.todo_list.setItem(r1, 1, QtWidgets.QTableWidgetItem(item[1]))
self.todo_list.setItem(r1, 2, QtWidgets.QTableWidgetItem(item[2]))
self.todo_list.resizeColumnsToContents()
labels = ["Id","Tasks","Date"]
self.todo_list.setHorizontalHeaderLabels(labels)
def add_task(self):
new_task = self.task_input.text()
new_date = self.date_input.text()
if len(new_task) == 0 or len(new_date) == 0:
self.info_label.setText("Please type in a task and a date")
self.info_label.adjustSize()
return None
self.info_label.setText("")
db_cursor.execute("INSERT INTO to_do(task,date) VALUES (:task,:date)",{'task':new_task,'date':new_date})
db.commit()
self.connect_database()
def remove_task(self):
#db_cursor.execute("INSERT INTO sqlite_sequence(seq) VALUES (0)")
selected = self.todo_list.selectedItems()
for index in selected:
idx = self.todo_list.item(index.row(),0)
idx = idx.text()
db_cursor.execute(f"DELETE FROM to_do WHERE id = {idx} ")
db_cursor.execute("delete from sqlite_sequence where name='to_do';")
db.commit()
self.todo_list.removeRow(index.row())
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "To-Do List"))
self.task_input.setPlaceholderText(_translate("MainWindow", "Enter a task"))
self.date_input.setPlaceholderText(_translate("MainWindow", "Enter a date (xx/xx/xxxx)"))
self.add_button.setText(_translate("MainWindow", "Add"))
self.remove_button.setText(_translate("MainWindow", "Remove"))
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
MainWindow = QtWidgets.QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()
sys.exit(app.exec_())
Final Words
We took in some fascinating data through the article Python 3 PyQt5 Schedule Muck Application Utilizing SQLite Data set GUI Work area Application. Likewise on the off chance that you feel somewhat wary about this article you can report your questions as a remark box. Much appreciated