-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathsql_table.py
More file actions
41 lines (38 loc) · 1.36 KB
/
sql_table.py
File metadata and controls
41 lines (38 loc) · 1.36 KB
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
import sys
from PyQt5.uic import loadUi
from PyQt5 import QtWidgets
from PyQt5.QtWidgets import QDialog, QApplication
import sqlite3
class MainWindow(QDialog):
def __init__(self):
super(MainWindow, self).__init__()
loadUi("tabletutorial.ui",self)
self.tableWidget.setColumnWidth(0, 250)
self.tableWidget.setColumnWidth(1, 100)
self.tableWidget.setColumnWidth(2, 350)
self.tableWidget.setHorizontalHeaderLabels(["City","Country","Subcountry"])
self.loaddata()
def loaddata(self):
connection = sqlite3.connect('data.sqlite')
cur = connection.cursor()
sqlstr = 'SELECT * FROM worldcities LIMIT 40'
tablerow=0
results = cur.execute(sqlstr)
self.tableWidget.setRowCount(40)
for row in results:
self.tableWidget.setItem(tablerow, 0, QtWidgets.QTableWidgetItem(row[0]))
self.tableWidget.setItem(tablerow, 1, QtWidgets.QTableWidgetItem(row[1]))
self.tableWidget.setItem(tablerow, 2, QtWidgets.QTableWidgetItem(row[2]))
tablerow+=1
# main
app = QApplication(sys.argv)
mainwindow = MainWindow()
widget = QtWidgets.QStackedWidget()
widget.addWidget(mainwindow)
widget.setFixedHeight(850)
widget.setFixedWidth(1120)
widget.show()
try:
sys.exit(app.exec_())
except:
print("Exiting")