【问题标题】:linux desktop executable python scriptlinux桌面可执行python脚本
【发布时间】:2013-09-28 14:54:03
【问题描述】:

我尝试制作一个简单的 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 文件

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

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

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

我做错了什么?

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

谢谢

【问题讨论】:

    标签: python linux desktop


    【解决方案1】:

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

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

    在脚本底部按回车键关闭。

    【讨论】:

    • 还需要 12 分钟才能接受这个 ;)
    • 这是常用的方法吗?
    • 我想是的。但是,通常人们不会从快捷方式运行即时脚本。像Ranger 这样的程序已经可以长时间保持活动状态,而其他不这样的程序几乎从来没有这样运行过。 // 一些终端支持退出等待,但是你将自己锁定在几个终端中。这样你就可以使用所有的了。
    • 终端为空白
    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-05-08
      • 1970-01-01
      • 2014-03-26
      • 1970-01-01
      • 2022-11-02
      • 2022-10-19
      • 2010-10-28
      相关资源
      最近更新 更多