In file index.py this line works fine, but in imported class similar line won't work! I can't understand why. Here is code:
index.py
import sys
from PyQt5 import uic
from PyQt5.QtWidgets import QMainWindow, QApplication
class MainWindow(QMainWindow):
def __init__(self):
super().__init__()
# Set up the MainWindow from Designer.
uic.loadUi("mw.ui", self)
# Connect up the buttons.
self.pushButton.clicked.connect(self.BtnClck)
self.show()
def BtnClck(self):
# Set up the ContentWindow from Designer.
from form1 import form1
form1(self.mn_general)
self.mn_general.pushButton_2.clicked.connect(form1 .BtnClck1) #this works fine
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = MainWindow()
sys.exit(app.exec_())
form1.py
from PyQt5 import uic
class form1:
def __init__(self, obj):
super().__init__()
uic.loadUi("form1.ui", obj)
obj.pushButton.setText('TextChanged on init') #this works fine
obj.pushButton.clicked.connect(self.BtnClck1) #this NOT works
obj.pushButton.click() #this make previous line works fine!
def BtnClck1(self):
print('SecondWindowPrint')
Bookmarks