linux桌面可执行python脚本

时间:2013-09-28 14:54:03

标签: python linux desktop

我试图制作一个简单的python脚本可执行文件,因此用Google搜索了该怎么做。 这是我到目前为止所得到的

的.desktop

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

python文件

#!/usr/bin/env python
print('hello world')

在终端上我做了chmod + x test.py,现在可以通过./test.py

在终端中执行它了。

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

我做错了什么?

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

谢谢

2 个答案:

答案 0 :(得分:3)

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

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

在要关闭的脚本底部按下。

答案 1 :(得分:0)

@Veedrac这不是正确的方法。 正确的方法是使用time.sleep(),它在Python 3.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.