1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
| from PyQt5.QtWidgets import QApplication, QMainWindow, QWidget, QVBoxLayout, QPushButton, QMessageBox
import sys
import sqlite3
import os
class Bouton_simple(QPushButton):
def __init__(self, ui, texte):
super().__init__()
self.setStyleSheet("""QPushButton{font: 24px}""")
self.setText(texte)
class Fenetre_Principale(QMainWindow):
def __init__(self):
QMainWindow.__init__(self)
self.fenetre_widget = QWidget()
self.modif = Bouton_simple(self, texte="ajouter")
self.layout_vertical_global = QVBoxLayout()
self.layout_vertical_global.addWidget(self.modif)
self.fenetre_widget.setLayout(self.layout_vertical_global)
self.setCentralWidget(self.fenetre_widget)
self.modif.clicked.connect(self.add_line)
self.resize(800, 600)
self.connection = sqlite3.connect('Test_pour_Forum.db')
self.cursor = self.connection.cursor()
self.cursor.execute("""CREATE TABLE IF NOT EXISTS projects
([Col1] TEXT, [Col2] TEXT, [Col3] TEXT, [Col4] TEXT, [Col5] TEXT)""")
self.index = 0
self.name = os.getenv("LS_USER_FULLNAME")
self.show()
def add_line(self):
self.index = self.index + 1
data = (str(self.index), self.name, '3', "4", "5")
sql_add_query = """INSERT INTO projects VALUES""" + str(data)
try:
self.connection.execute(sql_add_query)
self.connection.commit()
full_row = ""
for row in self.cursor.execute("SELECT * FROM projects;"):
full_row = full_row + str(row) + "\n"
QMessageBox.information(self.fenetre_widget, "etat BD", str(full_row))
except Exception as erreur:
self.cursor.close()
QMessageBox.information(self.fenetre_widget, "KO", str(erreur))
if __name__ == "__main__":
appli = QApplication(sys.argv)
fenetre_main = Fenetre_Principale()
sys.exit(appli.exec_()) |
Partager