使用Pycharm+PyQt5弹出子窗口的程序代码
时间:2022-04-18 11:43:26|栏目:Python代码|点击: 次
用pycharm和pyqt5,想写一个弹出窗口的程序,如下:
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_())
如果测试时发现闪退,可以试着修改一下调用子窗口的程序:
把‘show'去掉:
def time1(self): print('rec start') self.nw=newin() #self.nw.show() self.nw.exex_()