PyQt:如何在 Raspberry Pi 桌面启动时运行 GUI? [英] PyQt: How to run GUI on Raspberry Pi desktop startup?

查看:52
本文介绍了PyQt:如何在 Raspberry Pi 桌面启动时运行 GUI?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的 Stackoverflow 社区,

Dear Stackoverflow community,

我正在努力运行一个 python 脚本,该脚本在使用 Raspbian Jessie 的 Raspberry Pi 3B 桌面启动时执行PyQt5 GUI.

I am struggling with running a python script that executes a PyQt5 GUI on desktop startup of Raspberry Pi 3B with Raspbian Jessie.

到目前为止我有什么?

  • 带有shebang #!/usr/bin/env python3 的Python 脚本在第一行(python3 --version 是3.4.2)运行GUI任何问题

  • Python script with shebang #!/usr/bin/env python3 in first line (python3 --version is 3.4.2) running the GUI without any problems

能够使用以下几行执行 GUI 的 Shell 脚本 (.sh):

Shell script (.sh) that is able to execute the GUI with the following lines:

#!/bin/bashpython3 GUI.py

可能有帮助的信息:

  • 如果我将两个文件放在同一目录中的某个位置,Shell 脚本会启动 GUI,但如果它们在桌面上,则不会.

  • If I place both files in the same directory somewhere, the Shell script starts the GUI, but if they are on the desktop, it doesn't.

已启用自动登录桌面.

在此先感谢您的帮助.

RaspiManu

更新:

我通过大量测试解决了我的问题,并为其他用户发布了答案.

I solved my Problem with a lot of testing and posted an answer for other users.

推荐答案

经过大量测试,我自己弄明白了.这是它对我的工作方式...

After a lot of testing, I figured it out myself. Here's how it worked for me...

创建自动运行文件:

2.1 LXTerminal:cd/home/pi/.config/autostart

2.1 LXTerminal: cd /home/pi/.config/autostart

2.2 LXTerminal:sudo nano pythonscript.desktop

2.2 LXTerminal: sudo nano pythonscript.desktop

2.3 pythonscript.desktop:

2.3 pythonscript.desktop:

[Desktop Entry]
Version=1.0
Name=YourName
Comment=Your comment
Exec=/home/pi/pythonscript.py -nograb #-nograb for comboBox on touch Screen
Icon=/usr/share/pixmaps/python.xpm
Path=/home/pi/
Terminal=false
StartupNotify=true
Type=Application
Categories=Utility;Application;

2.4 Ctrl+O、Ctrl+X、sudo reboot

2.4 Ctrl+O, Ctrl+X, sudo reboot

注意事项:

重要的是,您不能只使用脚本的任何路径.该脚本必须直接位于 /home/pi/ 目录中,因此您可以在自动运行文件 (.桌面).我还了解到,如果你的脚本加载了一个带有 PIL 的图像,这个图像必须在其他地方,也许在你的桌面上,因为它不能从 /home/pi/ 目录.

It is important, that you can't use just any path to your script. The script has to be directly in the /home/pi/ directory, so you would use Exec=/home/pi/pythonscript.py in the autorun-file (.desktop). I also learned, that if your script loads for example an image with PIL, this image has to be somewhere else, maybe on your desktop, because it can't be opened out of the /home/pi/ directory.

如果您的 GUI 具有组合框并且您使用的是触摸屏,则组合框可能会在您触摸它后使您的整个 GUI 无法使用.使用 Exec=/home/pi/pythonscript.py -nograb 解决了这个问题.

If your GUI has a comboBox and you are using a touch screen, the comboBox might make your whole GUI unuseable after you touched it. Using Exec=/home/pi/pythonscript.py -nograb solves this problem.

StartupNotify=true 对于启动 GUI 脚本很重要.

StartupNotify=true is important for starting GUI scripts.

希望这会有所帮助,

RaspiManu

这篇关于PyQt:如何在 Raspberry Pi 桌面启动时运行 GUI?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆