Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8815003
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T04:16:03+00:00 2026-06-14T04:16:03+00:00

I have a problem opening new window in my python gui app. I have

  • 0

I have a problem opening new window in my python gui app. I have 3 classes (first login is shown, and than 2 windows are opened). This works fine:

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_())

I need viewer to be executed from MainWindow but when I put it like this it just flashes and disappear:

class MainWindow(QtGui.QMainWindow):
        def __init__(self, parent = None):
                QtGui.QWidget.__init__(self, parent)
        .....
        def DoOpenImageViewer(self):
                viewer = ImageViewerMainWindow("C:\image.jpg")
                viewer.show()
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T04:16:04+00:00Added an answer on June 14, 2026 at 4:16 am

    You need to keep a reference to you viewer, otherwise the new window is destroyed when viewer goes out of scope and is garbage collected.
    If you only need one Window at a time, you can do something like:

    class MainWindow(QtGui.QMainWindow):
            def __init__(self, parent = None):
                    QtGui.QWidget.__init__(self, parent)
            .....
            def DoOpenImageViewer(self):
                    self.viewer = ImageViewerMainWindow("C:\image.jpg")
                    self.viewer.show()
    

    Otherwise you could use a list to store the references.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem with IE8 and the opening of a new window with
have a a problem with opening a new window using javascript. In Chrome and
I have a problem with opening CF.NET forms using VSTS 2008. It uses the
I have a problem here with this code. I'm opening a socket, then listening
well I have that problem, im using a lightbox srcipt and im opening an
I have problem with show or hide form in Window Form Application. I start
I have a brand new server with Windows 2008 Server 64 bit + SQL
I have a problem with browsers window managament with javascript. I have two page
I have a problem with opening one more stage in another thread. No exceptions
I'm a new to phonegap and are having a problem opening the native google

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.