I'm new to python. I designed a GUI in QtDesigner and translated the code to use it with python. Since if I change something in the GUI it will overwrite my code I want to use a separate file for the functions.
The code should run after the main window is shown but I get an error
Ui_MainWindow' object has no attribute 'fillContactList'
I would really appreciate if anyone would help me.
import sys
import psycopg2
from PySide6 import (QtCore, QtWidgets, QtGui)
from PySide6.QtCore import (QCoreApplication, QDate, QDateTime, QLocale,
QMetaObject, QObject, QPoint, QRect,
QSize, QTime, QUrl, Qt)
from PySide6.QtGui import (QBrush, QColor, QConicalGradient, QCursor,
QFont, QFontDatabase, QGradient, QIcon,
QImage, QKeySequence, QLinearGradient, QPainter,
QPalette, QPixmap, QRadialGradient, QTransform)
from PySide6.QtWidgets import (QApplication, QLabel, QMainWindow, QMenuBar,
QSizePolicy, QStatusBar, QTabWidget, QWidget)
from mainwindow import Ui_MainWindow
class mainwindow(QMainWindow, Ui_MainWindow):
def __init__(self):
super(mainwindow, self).__init__()
self.setWindowTitle("Skills In Motion")
def fillContactList(self):
conn = psycopg2.connect(database="CRM", user="********", password="*****", host="localhost", port=5432)
cur = conn.cursor()
dataset = cur.execute("SELECT cust_name, cust_pk FROM customer")
results = cur.fetchall()
rowPosition = 0
for customers in results:
self.contactsTable.insertRow(rowPosition)
self.contactsTable.setItem(rowPosition,0,QtWidgets.QTableWidgetItem(customers[0]))
self.contactsTable.setItem(rowPosition,1,QtWidgets.QTableWidgetItem(str(customers[1])))
self.contactsTable.hideColumn(1)
rowPosition = rowPosition+1
self.contactsTable.itemSelectionChanged.connect(self.onSelectionContact)
self.contactsTable.selectRow(0)
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
MainWindow = QtWidgets.QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
ui.fillContactList()
MainWindow.show()
sys.exit(app.exec())```