大家好。
我正在使用python3.4和PyQt5在Windows 7上制作GUI应用程序。
这个应用程序非常简单。用户点击主窗口的按钮,信息对话框就会弹出。当用户点击信息对话框的关闭按钮(窗口的X按钮),系统会显示确认消息。就是这样。
以下是我的代码。
# coding: utf-8
import sys
from PyQt5.QtWidgets import QApplication, QMainWindow, QPushButton, QDialog, QLabel
class mainClass(QMainWindow):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
openDlgBtn = QPushButton("openDlg", self)
openDlgBtn.clicked.connect(self.openChildDialog)
openDlgBtn.move(50, 50)
self.setGeometry(100, 100, 200, 200)
self.show()
def openChildDialog(self):
childDlg = QDialog(self)
childDlgLabel = QLabel("Child dialog", childDlg)
childDlg.resize(100, 100)
childDlg.show()
if __name__ == "__main__":
app = QApplication(sys.argv)
mc = mainClass()
sys.exit(app.exec_())
结果屏幕截图是...
在这种情况下,我已经在mainClass类中添加了这些代码。
def closeEvent(self, event):
print("X is clicked")
这段代码仅在主窗口关闭时运行。但是我想让closeEvent函数在childDlg关闭时运行,而不是在主窗口中运行。
我该怎么办?