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

kpie
  • 9,588
  • 5
  • 28
  • 50
Eoin
  • 357
  • 1
  • 4
  • 20

2 Answers2

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

Community
  • 1
  • 1
  • Perfect thank you, this link helped, I overrode the closeEvent() method to clean up the close process – Eoin Apr 22 '16 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())
user2549818
  • 199
  • 1
  • 5