Use Pycharm+PyQt5 pop up sub window program code

  • 2021-12-09 09:13:58
  • OfStack

With pycharm and pyqt5, I want to write a pop-up window program, as follows:


class video_record(QWidget):
    def __init__(self):
        super().__init__()
        self.initUI()
    def initUI(self):
        self.startbtn=QPushButton('begin',self)
        self.startbtn.setGeometry(40,20,100,20)
        self.startbtn.clicked.connect(self.time1)

        self.timeshow=QLineEdit('',self)
        self.timeshow.setGeometry(200,200,100,20)

        self.setGeometry(100,100,640,480)
        self.setWindowTitle('rec')
        self.show()

    def time1(self):
        print('rec start')
        self.nw=newin()
        self.nw.show()
        self.nw.exex_()
    
class newin(QDialog):
    def __init__(self):
        super().__init__()
        self.initUI()
    def initUI(self):
        self.lblx=QLabel('hh',self)
        self.lblx.setGeometry(100,100,100,20)
        self.lblx.setAutoFillBackground(True)
        self.pale=QPalette()
        self.pale.setColor(QPalette.Window,Qt.blue)
        self.lblx.setPalette(self.pale)
        self.setGeometry(100,100,300,300)
        self.setWindowTitle('newin')
        self.show()
if __name__ == '__main__':
    app=QApplication(sys.argv)
    ex=video_record()
    ex.show()
    sys.exit(app.exec_())

If you find a flashback during the test, you can try modifying the program that calls the child window by 1:
Remove 'show':


def time1(self):
        print('rec start')
        self.nw=newin()
        #self.nw.show()
        self.nw.exex_()

Related articles: