简体   繁体   English

如何使用Tkinter在树莓派中自动启动python

[英]How can I autostart python in raspberry with Tkinter

I am writing a python program with tkinter in RPI. 我正在RPI中用tkinter编写python程序。 I want to Autostart this program on boot, but it keeps error on: Error Message PS:I didn't using any matlab on this program. 我想在启动时自动启动该程序,但会保持错误状态: 错误消息 PS:我在此程序上未使用任何matlab。

Raspbian? Raspbian? I just used the autostart file to do this. 我只是使用自动启动文件来执行此操作。 Edit /home/pi/.config/lxsession/LXDE-pi/autostart and add: 编辑/home/pi/.config/lxsession/LXDE-pi/autostart并添加:

@/home/pi/path/to/myprogram.py

Be sure to include a shebang in your file. 确保在文件中包含shebang。 Then set the executable bit with this command: 然后使用以下命令设置可执行位:

chmod +x /home/pi/path/to/myprogram.py

Edit: That error looks like you are trying to run your program remotely, via ssh or something. 编辑:该错误似乎您正在尝试通过ssh或其他方式远程运行程序。 I don't think that error is related to the autostart. 我认为该错误与自动启动无关。 If you want to run the program via ssh, you need to type this command first: 如果要通过ssh运行程序,则需要先键入以下命令:

export DISPLAY=:0

This works for me: 这对我有用:

cd /home/pi/.config/autostart    

Then create new file: 然后创建新文件:

sudo nano pythonprogramm.desktop

(you can replace "pythonprogramm") (您可以替换“ pythonprogramm”)

And you write this in the new file: 然后将其写入新文件:

[Desktop Entry]
Encoding=UTF-8
Type=Application
Name=pythonprogramm
#Exec=sudo idle /var/www/html/pythonprogramm.py
Exec=sudo /var/www/html/pythonprogramm.py
StartupNotify=false
Terminal=yes
Hidden=false

Reboot and it should work :) 重新启动,它应该工作:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM