-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
32 lines (27 loc) · 941 Bytes
/
main.py
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
import sys
import sqlite3
from PyQt5.QtWidgets import QApplication, QMainWindow, QTableWidgetItem
from PyQt5 import uic
class MyWidget(QMainWindow):
def __init__(self):
super().__init__()
uic.loadUi('ui.ui', self)
self.con = sqlite3.connect("coffee.db")
self.run()
def run(self):
cur = self.con.cursor()
res = cur.execute("SELECT * FROM coffee").fetchall()
self.tableWidget.setColumnCount(7)
self.tableWidget.setRowCount(0)
for i, row in enumerate(res):
self.tableWidget.setRowCount(
self.tableWidget.rowCount() + 1)
for j, elem in enumerate(row):
self.tableWidget.setItem(
i, j, QTableWidgetItem(str(elem)))
self.tableWidget.resizeColumnsToContents()
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = MyWidget()
ex.show()
sys.exit(app.exec_())