简体   繁体   中英

How to run a Python 3 tkinter app without opening any Terminal windows in Mac OS X?

I developed a GUI app in Python 3. I want to be able to launch it by clicking on the script itself or in a custom-made launching script. I have changed permissions and it's now opening with "Python Launcher" on double-click. But everytime I run my app, I get a lot of windows:

  • My Python application (that's the only one I need to be on screen)

  • The Python launcher preferences (I could live with this one, but would prefer it to be hidden)

  • A Terminal window with the default shell (don't need this one)

  • Another Terminal window showing the output of the app (like print , errors... I don't want this window)

What is the easiest way to get only the GUI on screen, without any Terminal windows?

Following the suggestion bu linusg, I discovered that I can accomplish this by creating an AppleScript application with the following code (adjusting the paths of python3 and of the Python application as needed):

do shell script "export LC_ALL=en_US.UTF-8; export LANG=en_US.UTF-8; /usr/local/bin/python3 '/Users/USER/FOLDER/SCRIPT.py' &> /dev/null &"

It launches the Python application without Terminal Windows. The AppleScript application can then be personalised with a custom icon as usual, and can be placed in the Dock. When clicked, it will launch the Python intepreter, that still shows up in Dock, but with no visible windows.

I think this may be useful to other users.

By changing the file extension to .pyw (Python Windowed), any terminal/shell/cmd would be hidden by default (I even don't know about the preferences window).

Hope this helps!

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