终止PyQt应用 [英] Terminate PyQt Application
本文介绍了终止PyQt应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果用户与应用程序进行交互(例如,按下按钮),然后用户单击X按钮,则应用程序将继续运行,但窗口将关闭.如何完全终止该应用程序.它是使用PyQt5构建的.
If the user interacts with the application, for example pressing a button, and the user clicks then on the X button, the application keeps running, but the window closes. How can I fully terminate the application. It’s built using PyQt5.
推荐答案
尝试一下:
import sys
from PyQt5.QtWidgets import (QMainWindow, QLabel, QGridLayout, qApp,
QApplication, QWidget, QPushButton)
from PyQt5.QtCore import QSize, Qt
class HelloWindow(QMainWindow):
def __init__(self):
super().__init__()
self.setWindowTitle("Hello world")
centralWidget = QWidget()
self.setCentralWidget(centralWidget)
title = QLabel("Hello World from PyQt")
title.setAlignment(Qt.AlignCenter)
button = QPushButton("Quit")
button.clicked.connect(qApp.quit) # <---
gridLayout = QGridLayout(centralWidget)
gridLayout.addWidget(title, 0, 0)
gridLayout.addWidget(button, 1, 0)
if __name__ == "__main__":
app = QApplication(sys.argv)
mainWin = HelloWindow()
mainWin.show()
sys.exit( app.exec_() )
这篇关于终止PyQt应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文