简体   繁体   English

如何运行Python 3 tkinter应用程序而无需在Mac OS X中打开任何终端窗口?

[英]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. 我在Python 3中开发了一个GUI应用程序。我希望能够通过单击脚本本身或在定制的启动脚本中启动它。 I have changed permissions and it's now opening with "Python Launcher" on double-click. 我已经更改了权限,现在双击打开“Python Launcher”。 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) 我的Python应用程序(这是我需要在屏幕上唯一的应用程序)

  • The Python launcher preferences (I could live with this one, but would prefer it to be hidden) Python启动器首选项(我可以使用这个,但更喜欢隐藏它)

  • A Terminal window with the default shell (don't need this one) 带有默认shell的终端窗口(不需要这个)

  • Another Terminal window showing the output of the app (like print , errors... I don't want this window) 另一个终端窗口显示应用程序的输出(如print ,错误......我不想要这个窗口)

What is the easiest way to get only the GUI on screen, without any Terminal windows? 在没有任何终端窗口的情况下,只在屏幕上显示GUI的最简单方法是什么?

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): 根据bu linusg的建议,我发现我可以通过使用以下代码创建AppleScript应用程序来完成此任务(根据需要调整python3和Python应用程序的路径):

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. 它启动没有Terminal Windows的Python应用程序。 The AppleScript application can then be personalised with a custom icon as usual, and can be placed in the Dock. 然后可以像往常一样使用自定义图标对AppleScript应用程序进行个性化,并将其放置在Dock中。 When clicked, it will launch the Python intepreter, that still shows up in Dock, but with no visible windows. 单击时,它将启动Python解释器,它仍然显示在Dock中,但没有可见的窗口。

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). 通过将文件扩展名更改为.pyw (Python Windowed),默认情况下将隐藏任何终端/ shell / cmd(我甚至不知道首选项窗口)。

Hope this helps! 希望这可以帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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