linux桌面可执行python脚本

linux桌面可执行python脚本,python,linux,desktop,Python,Linux,Desktop,我试图制作一个简单的python脚本可执行,因此谷歌搜索了该怎么做。 这是我到目前为止得到的 .桌面 [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'

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

.桌面

[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脚本


谢谢

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

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

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

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

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.

@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.

需要12分钟才能接受此项;)这是常见的方法吗?我想是的。不过,通常人们不会从快捷方式运行即时脚本。像这样的程序已经存在很长一段时间,而其他不存在的程序几乎永远不会像这样运行一些终端支持等待出口,但您将自己锁定在少数终端中。这样你就可以全部使用了。终端是空的,你还需要12分钟来接受这个;)这是常见的方法吗?我想是的。不过,通常人们不会从快捷方式运行即时脚本。像这样的程序已经存在很长一段时间,而其他不存在的程序几乎永远不会像这样运行一些终端支持等待出口,但您将自己锁定在少数终端中。这样你就可以全部使用。终端是空的