0

I have created an exe of a python program with cx_Freeze.
I have used PyQt4 to create a GUI.

It opens perfectly, an empty console first and then the GUI.
However when I close the GUI (after running the program or not) the console remains open. If I click on any part of the console it gives me the error popup "MyProgram has stopped working"

This has been tested on a system (Win7-64bit) with a python install (3.4.4) and another system with no python (Win7-64bit).

Is there a way that I can close this console after the GUI is closed? or better yet...How do I close the console?

DevEnv
Python : 3.4
OS : Windows 7

Edit :

I managed to find a work around.....in my close_application method I included lines that use psutil to kill a process. This works when I close through a UI button but not if I click the "x" in the top right of the window

Thank you

2 Answers 2

1

I think you need to link the event of clicking the "x" top right button with the killing process lines.

This topic may be of help? PySide / PyQt detect if user trying to close window

1
  • Perfect thank you, this link helped, I overrode the closeEvent() method to clean up the close process
    – Eoin
    Apr 22, 2016 at 13:11
0

I am using wxPython and faced the same issue. The solution I found was to wrap the main function in a sys.exit clause. So my main.py looks something like this:

import sys
import wx

class MyFrame(wx.Frame):
    def __init__(self):
        """Constructor"""
        wx.Frame.__init__(self, None, title="Close Me")
        panel = wx.Panel(self)

        closeBtn = wx.Button(panel, label="Close")
        closeBtn.Bind(wx.EVT_BUTTON, self.onClose)

    def onClose(self, event):
        self.Destroy()

def main():
    app = wx.App(False)
    frame = MyFrame()
    frame.Show()
    app.MainLoop()


if __name__ == '__main__':
    sys.exit(main())

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.