1

so i am running python 3.5 and spyder 3.2.8 and pyinstaller i have made a gui with designer used the main thats shows below.

def run():
    app=QtWidgets.QApplication(sys.argv)
    MainWindow = QtWidgets.QMainWindow()
    ui = Ui_Dialog()
    ui.setupUi(MainWindow)
    MainWindow.show()
    sys.exit(app.exec_())

run()

my question is about that when i use the pyinstaller to make the exe i run it and a console pop ups along with the gui and when i close it, all the gui closes. any idea?

nandal
  • 2,544
  • 1
  • 18
  • 23
iMBLISH
  • 65
  • 2
  • 7
  • Is your indentation in your program as shown here? – Jonathan Jun 12 '18 at 07:30
  • no just copied it like that the program works as it should but my problem is that a console is open too and i want only the gui to show. – iMBLISH Jun 12 '18 at 07:32
  • Possible duplicate of [How to hide console window in python?](https://stackoverflow.com/questions/764631/how-to-hide-console-window-in-python) – Karsten Koop Jun 12 '18 at 07:55
  • @KarstenKoop according to the answer (@iMBLISH please accept the answer) to use an argument, it doesn't seem as a duplicate. Voting to leave open. – Eldelshell Jun 12 '18 at 10:20

2 Answers2

3

Use '--noconsole' argument while creating your .exe using pyinstaller

refer documentation for more details:-http://pyinstaller.readthedocs.io/en/stable/usage.html

nandal
  • 2,544
  • 1
  • 18
  • 23
0

I think you need to indent it properly to have your code only execute when run() is invoked.

def run():
    app=QtWidgets.QApplication(sys.argv)
    MainWindow = QtWidgets.QMainWindow()
    ui = Ui_Dialog()
    ui.setupUi(MainWindow)
    MainWindow.show()
    sys.exit(app.exec_())

run()
Jonathan
  • 748
  • 3
  • 20
  • remove your answer before someone starts downvoting... the code will not run without indentation – Avezan Jun 12 '18 at 07:33
  • 1
    copied it wrong i have it like that the gui shows and works but a console is also open and i want only the gui to show. – iMBLISH Jun 12 '18 at 07:33