Я новичок в python, и я работаю над личным проектом по управлению моей мастерской. У меня есть QDialog.ui с табличным виджетом, который я хочу заполнить запросом к SQL Server в файле с именем DBtest.py, и у меня естьмой основной файл Index_test.py, но я не могу сообщить обоим, может ли кто-нибудь дать мне подсказку?
main index_test.py
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
import sys
import DBtest
from PyQt5.uic import loadUiType
import pyodbc
ui,_ = loadUiType('Simple.ui')
class MainApp(QDialog , ui):
def __init__(self):
QDialog.__init__(self) #sacar en nombre del UI
self.setupUi(self) #muestra el ui en esta aplicacion
def Show_Table():
DBtest.Show_Clientes(data)
def main():
app = QApplication(sys.argv)
window = MainApp()
window.show()
app.exec_()
if __name__ == '__main__':
main()
DBtest.py
class ShowData():
def Show_Clientes(self):
self.db = pyodbc.connect('Driver={SQL Server};'
'Server=PC-ROMO-INGENIE\MTDB;'
'Database=dbsistema;'
'Trusted_Connection=yes;')
self.cursor = self.db.cursor()
self.cursor.execute ('''SELECT nombre, RFC, descripcion, direccion, telefono, email FROM cliente Where tipo_cliente = 'Cliente' ''')
data = self.cursor.fetchall()
if data :
self.tableWidget.setRowCount(0)
self.tableWidget.insertRow(0)
for row , form in enumerate(data):
for column , item in enumerate(form):
self.tableWidget.setItem(row , column , QTableWidgetItem(str(item)))
column += 1
row_position = self.tableWidget.rowCount()
self.tableWidget.insertRow(row_position)