Python PySide Qt Creator消息对话框退出
因此,我用QtCreator创建了一个ui文件,其中包括一个QPushButton。出于测试目的,我想弹出一个QMessageDialog,它说hello!在主窗口类中打开ui后,我将该按钮从ui连接到def hello(self): 后来Python PySide Qt Creator消息对话框退出,python,qt-creator,pyside,Python,Qt Creator,Pyside,因此,我用QtCreator创建了一个ui文件,其中包括一个QPushButton。出于测试目的,我想弹出一个QMessageDialog,它说hello!在主窗口类中打开ui后,我将该按钮从ui连接到def hello(self): 后来 def hello(self): QtGui.QMessageBox.question(self,'Message',"hello!",QtGui.QMessageBox.Ok) 当我在消息对话框中单击“ok”后,会弹出一条消息说“hello!”,
def hello(self):
QtGui.QMessageBox.question(self,'Message',"hello!",QtGui.QMessageBox.Ok)
当我在消息对话框中单击“ok”后,会弹出一条消息说“hello!”,整个python程序退出,从而导致主窗口GUI崩溃
当我不使用UI文件时,这并没有发生在我身上。有人知道为什么会这样吗
提前谢谢
编辑:我一单击“确定”就会发生这种情况
回溯(最近一次呼叫最后一次):
文件“C:\Users\George\Desktop\loadui..py”,第25行,在
main()
文件“C:\Users\George\Desktop\loadui..py”,第23行,主目录
sys.exit(app.exec_())
系统出口:0
将QDialog
的父级从self
更改为QtGui.QApplication.activeWindow()
对我很有效。你能说得具体一点吗?是否显示了任何错误消息?好的……那么您可以发布您的main
?所以我们可以试着给你一个正确的解释…我想出来了,谢谢,我把UI改成了wdiget,然后在主窗口中有一个QMainWindow,并使用setCentralWidgetSo,问题出在哪里app.exec(
返回0,对吗?放置一个sys.exit
可能不是最好的主意,因为它告诉Python退出,你不觉得吗?pyside上的所有教程都有,我以前没有遇到过任何问题
def hello(self):
QtGui.QMessageBox.question(self,'Message',"hello!",QtGui.QMessageBox.Ok)
Traceback (most recent call last):
File "C:\Users\George\Desktop\loadui..py", line 25, in <module>
main()
File "C:\Users\George\Desktop\loadui..py", line 23, in main
sys.exit(app.exec_())
SystemExit: 0