Merhaba arkadaslar,
Menubar kullanarak tıkladıgımız bir menude aynı pencere içinde py dosyasını nasıl acabilirim.
yonetici.py
import os
from PyQt5 import QtWidgets
from _ui._yonetici_paneli_form import Ui_MainWindow
import sys
class yonetici(QtWidgets.QMainWindow):
def init(self):
super(yonetici, self).init()
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
self.ui.menubar.triggered.connect(self.firmacalisan)
def firmacalisan(self):
def app():
app = QtWidgets.QApplication(sys.argv)
win = yonetici()
win.show()
sys.exit(app.exec_())
app()
anasayfa.py
from PyQt5 import QtWidgets
from _ui._anasayfaForm import Ui_MainWindow
import sys
import mysql.connector
from PyQt5.QtWidgets import QTableWidgetItem
import os
class anasayfa(QtWidgets.QMainWindow):
def init(self):
super(anasayfa,self).init()
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
self.veriYukle()
self.ui.btnkEkle.clicked.connect(self.a)
self.ui.btnkSil.clicked.connect(self.delete)
self.ui.pushButton_4.clicked.connect(self.veriYukle)
self.ui.btnExit.clicked.connect(self.exit)
def exit(self):
quit()
def a(self):
os.system("kullanici_ekle.py")
def delete(self):
for item in self.ui.tableWidget.selectedItems():
print(item.row(),item.column(),item.text())
baglanti = mysql.connector.connect(
host="localhost",
user="root",
password="Wweefg_12*",
database="otomasyon",
auth_plugin="mysql_native_password"
)
cursor = baglanti.cursor()
sql = "delete from kullanicilar where kAdi =%s"
values = (item.text(),)
self.ui.label.setText("{0} Adılı kullanıcının kayıdı silinmiştir".format(item.text()))
cursor.execute(sql,values)
baglanti.commit()
def veriYukle(self):
baglanti = mysql.connector.connect(
host="localhost",
user="root",
password="Wweefg_12*",
database="otomasyon",
auth_plugin="mysql_native_password"
)
cursor = baglanti.cursor()
sql = "select * from kullanicilar"
cursor.execute(sql)
result = cursor.fetchall()
self.ui.tableWidget.setRowCount(len(result))
self.ui.tableWidget.setColumnCount(4)
self.ui.tableWidget.setHorizontalHeaderLabels(("id","Çalışan Adı","Çalışan Soyadı","Maaş"))
tablerow = 0
for row in result:
print(row)
self.ui.tableWidget.setItem(tablerow, 0, QtWidgets.QTableWidgetItem(str(row[0])))
self.ui.tableWidget.setItem(tablerow, 1, QtWidgets.QTableWidgetItem(row[1]))
self.ui.tableWidget.setItem(tablerow, 2, QtWidgets.QTableWidgetItem(row[2]))
self.ui.tableWidget.setItem(tablerow, 3, QtWidgets.QTableWidgetItem(str(row[3])))
tablerow +=1
def app():
app = QtWidgets.QApplication(sys.argv)
win = anasayfa()
win.show()
sys.exit(app.exec_())
anasayfa.app()
bu da cagırmak istediğim py dosyası