网络编程
位置:首页>> 网络编程>> Python编程>> 使用Pycharm+PyQt5弹出子窗口的程序代码

使用Pycharm+PyQt5弹出子窗口的程序代码

作者:机构师  发布时间:2022-03-09 20:15:17 

标签:Pycharm,PyQt5,子窗口

用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_()

来源:https://blog.csdn.net/normer123456/article/details/120727896

0
投稿

猜你喜欢

手机版 网络编程 asp之家 www.aspxhome.com