Tkinter program converted to .app using PyInstaller closes immediately
Asked Answered
N

3

6

Have a Tkinter battleship game application I wrote that I am trying to convert to an .app file so I can run it easily on Mac OS X computers. After using cd to navigate to the directory with both the main .py file, and all the subfiles (three other Python files, a json file, and an icon file), I am executing the following command:

pyinstaller --onefile --windowed --icon favicon.icns --name Battleship battleship.py

This produces two files in the "dist" folder: Battleship and Battleship.app. The Battleship.app has the icon I specified in the command above.

When I run the non .app file (via double-clicking it), a terminal window opens and my Tkinter GUI opens and works (from the little testing I did) flawlessly. However, I would like only the GUI to open, without the terminal.

This is supposedly the purpose of also producing the .app file. However, when I run the .app file (via double-clicking it), it's icon merely bounces a few times in my application bar at the bottom of my screen, and then disappears. No actual window is opened.

How do I make it so when I double-click the .app file, my application's GUI actually opens (without a terminal window)?

Using Python 3.5.1.

Non answered 7/6, 2016 at 21:0 Comment(1)
You can use the --noconsole option in your terminal command to avoid showing the terminal window in your compiled .app file.Avenge
U
0

RoberR seems like you are missing some necessary packages while building app from pyInstaller, I would suggest your to use:

pyinstaller --onefile --icon favicon.icns --name Battleship battleship.py 

it will display your terminal and you would be able to figure out what is happening, in case of missing package please use:

pyinstaller --onefile --hidden-imports=file_name --icon favicon.icns --name Battleship battleship.py

Hope this solves your problems.

Ulrich answered 19/5, 2017 at 10:21 Comment(0)
R
0

It is definitely an issue with Tkinter that crash when using the doubleclick on the .app. The only workaround I found was to use "brew python3" instead of "anaconda python3".

Rb answered 1/2, 2019 at 15:49 Comment(0)
R
0

Reposting myself from: https://mcmap.net/q/1919425/-pyinstaller-executable-doesn-39-t-show-gui

There is a few issues with the tcl version that comes with python, discussed here. I've written an script that automatically changes the init.tcl file to the correct version.

N.B. you shouldn't use the --onefile flag as the file directories aren't present, and the script won't work.

  1. cd /path/of/your/app
  2. git clone https://github.com/jacob-brown/TCLChanger.git
  3. pyinstaller --windowed app.py
  4. python TCLChanger/TCLChanger.py

You should now be able to open your app, from the terminal and via double clicking.

Rigging answered 6/9, 2019 at 9:3 Comment(1)
I tried this and I get this error: UnboundLocalError: local variable 'fileTCL' referenced before assignmentPlease

© 2022 - 2024 — McMap. All rights reserved.