Linux桌面可执行Python脚本

2024-06-30 17:05:58 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图使一个简单的python脚本可执行,因此在google上搜索该怎么做。 这是我目前所得到的

.桌面

[Desktop Entry]
Version=1.0
Type=Application
Name=helloworld
Comment=
Exec=./test.py
Icon=
Path=/home/xxx/Desktop
Terminal=true
StartupNotify=false

python文件

^{pr2}$

在终端上我做了chmod+x测试.py现在可以通过在终端中执行它/测试.py在

如果我双击桌面图标,我可以看到终端打开了很短的时间,但很快就关闭了。在

我做错什么了?在

我希望桌面图标打开终端,然后显示我的python脚本。在

谢谢你


Tags: namepy脚本终端applicationversiontypegoogle
2条回答

脚本完成后,终端窗口将关闭。你可以把

input()     # Python 3
raw_input() # Python 2

在脚本底部按enter键关闭。在

@Veedrac这不是正确的方法。 正确的方法是使用time.sleep(),它在python3.x和2.x中都能工作。 使用下面的代码来执行此操作。在

import time # Should be the first statement.
# Some code is below. This code is useless. 
print()
def blah():
    print('bhahfdjfdk')
blah()
# When the program ends, use the code below to keep it running for some more time.
time.sleep(2) # In the parentheses you can replace 2 with the number of seconds you want to put the program on hold. This will help you and is the official Python way.

相关问题 更多 >