【发布时间】:2017-12-27 05:54:23
【问题描述】:
我正在使用 PyQT 创建 QMainWindow 窗口,该窗口在单击按钮时会打开另一个窗口。我的问题是,即使我关闭了生成它的主窗口,弹出窗口仍然显示。这与发布的here 非常相似,但用 C++ 编写,我只能使用 Python。如何在 Python 中实现答案?这是我的代码:
from PyQt4.QtGui import *
from PyQt4.QtCore import *
import sys
class Pycryptor:
def mainGui(self):
app = QApplication(sys.argv)
#MainWindow
self.mainWin = QMainWindow()
self.mainWin.setGeometry(200,200,500,432)
self.mainWin.show()
#MenuBar
mainMenu = self.mainWin.menuBar()
mainMenu.setNativeMenuBar(False)
aboutMenu = mainMenu.addMenu('A&bout')
helpButton = QAction(QIcon(),'Help',self.mainWin)
helpButton.triggered.connect(self.helpPopup)
aboutMenu.addAction(helpButton)
sys.exit(app.exec_())
def helpPopup(self):
self.popup = HelpWindow()
self.popup.setGeometry(800,200,300,500)
self.popup.show()
class HelpWindow(QWidget):
def __init__(self):
QWidget.__init__(self)
if __name__ == '__main__':
p = Pycryptor()
p.mainGui()
【问题讨论】:
-
HelpWindow 对象 setParent MainWindow
-
对不起,你能告诉我怎么做吗?我刚刚开始学习课程
标签: python-3.x qt pyqt4