如何在启动时运行 python 程序(包含 tkinter) [英] How to run a python program(containing tkinter) on startup
本文介绍了如何在启动时运行 python 程序(包含 tkinter)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在树莓派启动时执行一个包含 tkinter 窗口的简单 python 脚本.并且 tkinter 窗口将出现在监视器上.假设我的简单脚本是
I want to execute a simple python script that contain tkinter window on start up of raspberry pi. and the tkinter window will appear on the monitor. suppose my simple script is
import Tkinter
from Tkinter import *
root = Tk()
root.mainloop()
我尝试了以下程序,但失败了
I have tried the following procedure and failed
mkdir ./bin
cd ./bin
sudo nano script_auto_run
然后写了下面的代码
#!/bin/bash
sudo python /home/pi/projects/test.py
为了让它可执行,我跑了
to make it executable i ran
sudo chmod 755 script_auto_run
编辑了 rc.local 文件
edited the rc.local file
sudo nano /etc/rc.local
并在 exit0 之前添加以下行
and added the following line before exit0
/home/pi/bin/script_auto_run
我做错了什么?
推荐答案
打开 /etc/profile
并把这一行放在底部
Open /etc/profile
and put this line at the bottom
sudo python /home/pi/projects/test.py
这篇关于如何在启动时运行 python 程序(包含 tkinter)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文