Объясните как обмениваться данными между формами ?? Почему по клику
self.pushButton.clicked.connect(self.aboutshow)
def aboutshow(self):
strq = self.lineEdit.text()
self.MyWin = StartMyMain()
self.MyWin.obr(strq)
print(strq)
self.close()
def obr(self,strs):
if strs:
self.ui.lineEdit.setText(strs)
Но в текстовом поле не отображается наша переменная strs. Очень прошу объясните почему? Учу питон недавно и работа моя от программирования далека, так что сильно не пинайте за такие вопросы.
Весь код целиком main.py
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import sys
import time
from gui import *
from gui2 import *
from PyQt5 import QtCore, QtGui, QtWidgets
class AboutUs(QtWidgets.QMainWindow, Ui_Form):
def __init__(self,parent=None):
super().__init__(parent, QtCore.Qt.Window)
self.setupUi(self)
self.pushButton.clicked.connect(self.aboutshow)
def aboutshow(self):
strq = self.lineEdit.text()
self.MyWin = StartMyMain()
self.MyWin.obr(strq)
print(strq)
self.close()
class StartMyMain(QtWidgets.QMainWindow):
def __init__(self, parent=None):
super().__init__(parent)
self.AboutUs = None
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
self.uiAbout = AboutUs()
self.ui.pushButton.clicked.connect(self.trik)
def trik(self):
self.aboutshow1 = AboutUs()
self.aboutshow1.show()
def obr(self,strs):
if strs:
self.ui.lineEdit.setText(strs)
if __name__ == "__main__":
app = QtWidgets.QApplication(sys.argv)
myapp = StartMyMain()
myapp.show()
sys.exit(app.exec_())
gui.py
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'gui.ui'
#
# Created by: PyQt5 UI code generator 5.5
#
# WARNING! All changes made in this file will be lost!
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(488, 352)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.lineEdit = QtWidgets.QLineEdit(self.centralwidget)
self.lineEdit.setGeometry(QtCore.QRect(30, 20, 421, 51))
self.lineEdit.setObjectName("lineEdit")
self.pushButton = QtWidgets.QPushButton(self.centralwidget)
self.pushButton.setGeometry(QtCore.QRect(120, 90, 251, 28))
self.pushButton.setObjectName("pushButton")
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 488, 26))
self.menubar.setObjectName("menubar")
MainWindow.setMenuBar(self.menubar)
self.statusbar = QtWidgets.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
self.pushButton.setText(_translate("MainWindow", "Вызвать форму"))
gui2.py
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'gui2.ui'
#
# Created by: PyQt5 UI code generator 5.5
#
# WARNING! All changes made in this file will be lost!
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_Form(object):
def setupUi(self, Form):
Form.setObjectName("Form")
Form.resize(400, 300)
self.pushButton = QtWidgets.QPushButton(Form)
self.pushButton.setGeometry(QtCore.QRect(60, 130, 281, 28))
self.pushButton.setObjectName("pushButton")
self.lineEdit = QtWidgets.QLineEdit(Form)
self.lineEdit.setGeometry(QtCore.QRect(20, 50, 351, 51))
self.lineEdit.setObjectName("lineEdit")
self.label = QtWidgets.QLabel(Form)
self.label.setGeometry(QtCore.QRect(80, 10, 291, 31))
self.label.setStyleSheet("font: 14pt \"MS Shell Dlg 2\";")
self.label.setObjectName("label")
self.retranslateUi(Form)
QtCore.QMetaObject.connectSlotsByName(Form)
def retranslateUi(self, Form):
_translate = QtCore.QCoreApplication.translate
Form.setWindowTitle(_translate("Form", "Form"))
self.pushButton.setText(_translate("Form", "Отобразить в главной форме"))
self.label.setText(_translate("Form", "Тут пишем текст"))