-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathmain.py
More file actions
40 lines (34 loc) · 1.27 KB
/
main.py
File metadata and controls
40 lines (34 loc) · 1.27 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
import sys
from PyQt5.uic import loadUi
from PyQt5 import QtWidgets
from PyQt5.QtWidgets import QDialog, QApplication
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.loaddata()
def loaddata(self):
people=[{"name":"John","age":45,"address":"New York"}, {"name":"Mark", "age":40,"address":"LA"},
{"name":"George","age":30,"address":"London"}]
row=0
self.tableWidget.setRowCount(len(people))
for person in people:
self.tableWidget.setItem(row, 0, QtWidgets.QTableWidgetItem(person["name"]))
self.tableWidget.setItem(row, 1, QtWidgets.QTableWidgetItem(str(person["age"])))
self.tableWidget.setItem(row, 2, QtWidgets.QTableWidgetItem(person["address"]))
row=row+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")