当前位置:   article > 正文

PyQt5 通过按钮关闭主窗口_pyqt5 窗口跳转后原窗关闭

pyqt5 窗口跳转后原窗关闭
# -*- coding: utf-8 -*- 
'''
    【简介】
    PyQT5中关闭窗体例子
 
  
'''

from PyQt5.QtWidgets import QMainWindow,QHBoxLayout, QPushButton ,  QApplication, QWidget  
import sys 

class WinForm(QMainWindow):  
   
   def __init__(self, parent=None):  
      super(WinForm, self).__init__(parent)
      self.resize(330,  100)  
      self.setWindowTitle('关闭主窗口例子')        
      self.button1 = QPushButton('关闭主窗口')       
      self.button1.clicked.connect(self.onButtonClick) 
        
      layout = QHBoxLayout()  
      layout.addWidget(self.button1)  
        
      main_frame = QWidget()  
      main_frame.setLayout(layout)    
      self.setCentralWidget(main_frame)  
  
   def onButtonClick(self ):  
        #sender 是发送信号的对象,此处发送信号的对象是button1按钮 
      sender = self.sender()         
      print( sender.text() + ' 被按下了' )  
      qApp = QApplication.instance()
      qApp.quit()
      
if __name__ == "__main__":  
   app = QApplication(sys.argv)  
   form = WinForm()  
   form.show()  
   sys.exit(app.exec_())
 

运行结果如下:










声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小小林熬夜学编程/article/detail/119574
推荐阅读
相关标签
  

闽ICP备14008679号