简体   繁体   中英

pyqt gui console keeps opening

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?

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()

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM