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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T02:34:38+00:00 2026-06-13T02:34:38+00:00

I have some trouble with creating window application using PyQt. For example: we have

  • 0

I have some trouble with creating window application using PyQt. For example: we have the following class for GUI:

class SampleMainWindow(QtGui.QMainWindow):   
    def __init__(self, parent=None):
         ...

    def hideEvent(self, event):
        ...

    def showEvent(self, event):
        ...

    def activate(self):
        ...

    def closeEvent(self, event):
        ...

What if we want to use it just for showing results and acept user inputs, and for all control logic we have another class, which use the instance of SampleMainWindow as a field:

class Programm:
    def __init__(self):
        self.window = SampleMainWindow()
        ....

app = QtGui.QApplication(sys.argv)
prog = Programm()
prog.window.show()
app.exec_()

So, if we create the instance of Programm, the application will run well, but on close we’ll get an error that python.exe process could not be completed normally. But if the instance of SampleMainWindow is not a field of class:

class Programm:
    def __init__(self):
        win = SampleMainWindow()
        ....

application close well. What’s the reason?

Here are the full version of Gui class:

class SampleMainWindow(QtGui.QMainWindow):

def initTray(self):
    self.icon = QtGui.QSystemTrayIcon()
    self.icon.setIcon(QtGui.QIcon('Tray.png'))
    self.icon.show()
    self.icon.activated.connect(self.activate)

def __init__(self, parent=None):
    QtGui.QMainWindow.__init__(self)
    moduleglobalconstants.APP_RUNNING = True
    self.initTray()
    self.newSession = True

    self.setGeometry(300, 300, 600, 400)
    self.setWindowTitle('Eye: Recently Added Lines')
    self.statusBar().showMessage('Ready')
    exitAction = QtGui.QAction(QtGui.QIcon('Exit.png')
            ,'Exit'
            ,self)

    exitAction.setShortcut('Ctrl+Q')
    exitAction.setStatusTip('Exit application')
    self.connect(exitAction
                ,QtCore.SIGNAL('triggered()')
                ,QtCore.SLOT('close()'))

    menubar = self.menuBar()
    fileMenu = menubar.addMenu('&File')
    fileMenu.addAction(exitAction)

    self.toolbar = self.addToolBar('Exit')
    self.toolbar.addAction(exitAction)

    self.textEdit = QtGui.QTextEdit()
    self.scrollPosition = self.textEdit.textCursor()
    self.textEdit.setReadOnly(True)
    self.setCentralWidget(self.textEdit)

def hideEvent(self, event):
    self.hidden = True
    self.setWindowFlags(QtCore.Qt.ToolTip)
    self.setVisible(False)

def showEvent(self, event):
    self.hidden = False
    self.setVisible(True)

def activate(self):

    self.setWindowFlags(QtCore.Qt.Window)
    self.show()
    self.setWindowState(self.windowState() & ~QtCore.Qt.WindowMinimized | QtCore.Qt.WindowActive)
    self.activateWindow()

def questionDialog(self, caption = 'Message',text = "Are you sure?"):
    self.activate()
    msgBox = QtGui.QMessageBox(self)
    msgBox.setWindowTitle("Eye")
    msgBox.setText(caption);
    msgBox.setInformativeText(text);
    msgBox.setStandardButtons(QtGui.QMessageBox.Yes| QtGui.QMessageBox.No);
    msgBox.setDefaultButton(QtGui.QMessageBox.Yes);
    return msgBox.exec_()

def criticalDialog(self,app, caption = 'Eye: Critical Error',text = "Impossible to continue working!"):
    self.activate()
    msgBox = QtGui.QMessageBox.critical(self,caption,text)
    moduleglobalconstants.APP_RUNNING = False

def closeEvent(self, event):
    reply = self.questionDialog()
    if reply == QtGui.QMessageBox.Yes:
        moduleglobalconstants.APP_RUNNING = False
        event.accept()
    else:
        event.ignore()

def showNewLines(self, singleLine = None, lines = None, mode='insert'):
    if (mode == 'rewrite'):
        self.textEdit.clear()
    if lines:
        for line in lines:
            self.textEdit.insertPlainText(line.strip() + "\n")
    elif singleLine:
        self.textEdit.insertPlainText(singleLine.strip()+"\n")
  • 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-13T02:34:39+00:00Added an answer on June 13, 2026 at 2:34 am

    This has to do with python’s garbage collecting – as (almost) soon an object isn’t referenced anymore it destroys it, so I guess the process doesn’t terminate as long as the window wasn’t garbage-collected.

    You can try to add at the end del Programm.window or something like that (there’s probably a better way of doing this, but I never programmed QT myself so I can’t help you here)

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

Sidebar

Related Questions

I am mlearning javascript and have some trouble creating an onject via prototype. I
I am having some trouble creating a seamless photo grid. I have searched the
I am creating a MVC4 application and I have got some troubles when I
I have some trouble with jquery ui-events: In my application, there are some sliders.
I have some trouble achieving adequate real-time performance from my application and wondering if
I'm having some trouble creating an object in C++. I create a class called
I have quite some trouble creating a WCF service that supports downloads of very
I'm creating an asteroids game and in my main class I'm having some trouble
I'm creating a Tabbed Application, and I'm having some trouble getting my icons to
I'm having some trouble creating a interface with Qt. i'd like to have a

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.