'python pyqt5 (use qt designer) but second window func not work

I have some problems with my pyqt5 code. I use the pyqt designer and separating my code.

per each program code is work well. but execute main program and call the second window, second window function not work.

I think this is simple problem but i don't know where fix it

QT_TEST2.py printing function is not work.

QT_TEST1.py

import sys 
import os
from PyQt5.QtWidgets import *
from PyQt5.uic import loadUiType
from QT_TEST2 import Second_Window

file_path = os.path.dirname(__file__)
form_class = loadUiType(os.path.join(file_path, "QT\\layout\\QT_TEST_UI1.ui"))[0]

class First_Window(QMainWindow, form_class):
    def __init__(self):
        super().__init__()
        self.setupUi(self)
        self.btn1.clicked.connect(self.OpenWindow)
    
    def OpenWindow(self):
        self.NewWindow = QMainWindow()
        self.ui =  Second_Window()
        self.ui.setupUi(self.NewWindow)
        self.NewWindow.show()

if __name__ == '__main__':
    app = QApplication(sys.argv)
    Main_Window = First_Window()
    Main_Window.show()
    app.exec_()

QT_TEST2.py

import sys
import os
from PyQt5.QtWidgets import *
from PyQt5.uic import loadUiType

file_path = os.path.dirname(__file__)
form_class = loadUiType(os.path.join(file_path, "QT\\layout\\QT_TEST_UI2.ui"))[0]

class Second_Window(QMainWindow, form_class):
    def __init__(self):
        super().__init__()
        self.setupUi(self)
        self.btn1.clicked.connect(self.printing)
    
    def printing(self):
        print("Hello Bro. You click this Button")

    

if __name__ == '__main__':
    app = QApplication(sys.argv)
    Second_Window = Second_Window()
    Second_Window.show()
    app.exec_()

please i need your reply. in advance thank you for your interesting



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source