我在我的 python gui 应用程序中打开新窗口时遇到问题。我有 3 个课程(显示第一次登录,然后打开了 2 个窗口)。这工作正常:
class LoginDialog(QtGui.QDialog):
def __init__(self, parent = None):
super(LoginDialog, self).__init__(parent)
.....
class MainWindow(QtGui.QMainWindow):
def __init__(self, parent = None):
QtGui.QWidget.__init__(self, parent)
.....
class ImageViewerMainWindow(QtGui.QMainWindow):
def __init__(self, path, parent = None):
super(ImageViewerMainWindow, self).__init__(parent)
.....
if __name__ == "__main__":
qtApp = QtGui.QApplication(sys.argv)
loginDlg = LoginDialog()
if not loginDlg.exec_():
sys.exit(-1)
MyMainWindow = MainWindow()
MyMainWindow.show()
viewer = ImageViewerMainWindow("C:\image.jpg")
viewer.show()
sys.exit(qtApp.exec_())
我需要从 MainWindow 执行查看器,但是当我这样放置时,它只会闪烁并消失:
class MainWindow(QtGui.QMainWindow):
def __init__(self, parent = None):
QtGui.QWidget.__init__(self, parent)
.....
def DoOpenImageViewer(self):
viewer = ImageViewerMainWindow("C:\image.jpg")
viewer.show()