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 8834677
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T09:04:38+00:00 2026-06-14T09:04:38+00:00

Basically I have a main window with a menu bar and a number of

  • 0

Basically I have a main window with a menu bar and a number of options . When I click on one of the options , my code should open another window. My code looks something like this now.
All required libraries are imported.

class subwindow(self):
    //Another small window

class MainWindow(QtGui.QMainWindow):
    def __init__(self):
        super(MainWindow , self).__init__()     
        self.window()

    def window(self):
         Action = QtGui.QAction(QtGui.QIcon('action.png') , 'action' , self)          
         Action.triggered.connect(self.a)

         mb = self.menuBar()
         option = mb.addMenu('File')
         option.addAction(Action)

         self.show()

   def a(self):
         s = subwindow()



if __name__ == '__main__':
    app = QtGui.QApplication(sys.argv)
    mw = MainWindow()
    sys.exit(app.exec_())

How do I run the sub-window part of the code.How do I add the QtGui.QApplication part?

  • 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-14T09:04:39+00:00Added an answer on June 14, 2026 at 9:04 am

    Like @Bakuriu said in the comments, there must be only one instance of QApplication. This starts the main event loop for the application.

    You can create a new window by deriving your SubWindow class from the QDialog class, and customizing it as you want.
    You need to call the exec_() method of the QDialog class to get the dialog to show.

    For example, in your code:

    from PyQt4 import QtGui
    import sys
    
    class SubWindow(QtGui.QDialog):
        def __init__(self):
            super(SubWindow , self).__init__()     
            label = QtGui.QLabel("Hey, subwindow here!",self);
    
    class MainWindow(QtGui.QMainWindow):
        def __init__(self):
            super(MainWindow , self).__init__()     
            self.window()
    
        def window(self):
            Action = QtGui.QAction(QtGui.QIcon('action.png') , 'action' , self)          
            Action.triggered.connect(self.a)
    
            mb = self.menuBar()
            option = mb.addMenu('File')
            option.addAction(Action)
    
            self.show()
    
        def a(self):
    
            s = SubWindow()
            s.exec_()
    
    if __name__ == '__main__':
        app = QtGui.QApplication(sys.argv)
        mw = MainWindow()
        sys.exit(app.exec_())
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically, I have somewhere in my main code where this line of code is
I basically have a program that filters records from one excel file to another
The title pretty much says it all, but basically I have a main parent
I have a main class(which is basically a netbeans form;drag and drop) from where
Basicily i have a index.html shown below.. <html> <head> <title>UI Test: Main Menu</title> <script
On my main window, I have several different buttons and fields that are already
I have a main window where I create the objects dynamically, so before making
I have a Cocoa application built using Garbage Collection with a main window. This
I have a class called GUIMain which registers, creates, and shows a main window
I have a main form ( form1 ). Within that form I successfully open

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.