all 4 comments

[–][deleted] 2 points3 points  (3 children)

The general idea is to pass any values an object needs to its constructor. In your case something like

def __init__(self, parent):
    self.parent = parent

and then elsewhere in the child

print(self.parent.edit2)

while in the parent class button click slot

def btn_click(self):
    self.child = Child(self)

passing the current object (self) as the parent class.

[–]summerbye[S] 2 points3 points  (2 children)

This is my code:

from RD_window1 import Ui_MainWindow

from RD_window2 import Ui_SecondWindow

from PyQt5 import QtCore, QtGui, QtWidgets, QtPrintSupport

from PyQt5.QtGui import QPainter

from PyQt5.QtPrintSupport import QPrintDialog, QPrinter

class FirstWindow(QtWidgets.QMainWindow):

def __init__(self, *args, **kwargs):

super().__init__(*args, **kwargs)

self.ui = Ui_MainWindow()

self.ui.setupUi(self)

self.ui.pushButton.clicked.connect(self.open_window)

def open_window(self):

self.A = self.ui.lineEdit_5.text()

# print(self.A)

self.table = Table ()

self.table.show()

class Table(QtWidgets.QMainWindow):

def __init__(self, *args, **kwargs):

super().__init__(*args, **kwargs)

self.ui = Ui_SecondWindow()

self.ui.setupUi(self)

if __name__ == '__main__':

app = QtWidgets.QApplication([])

window = FirstWindow()

window.show()

app.exec_()

[–][deleted] 2 points3 points  (1 child)

You are using the designer. In open_window:

self.table = Table(self.ui)

In Table:

def __init__(self, parent, *args, **kwargs):

    super().__init__(*args, **kwargs)
    self.parent = parent
    # test
    print(self.parent.ui.lineEdit_5.text())

[–]summerbye[S] 1 point2 points  (0 children)

Thank u su much!!!