How to run a python program(containing tkinter) on startup

房东的猫 提交于 2021-01-29 03:06:34

问题


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

then wrote the following code

#!/bin/bash
sudo python /home/pi/projects/test.py

to make it executable i ran

sudo chmod 755 script_auto_run

edited the rc.local file

sudo nano /etc/rc.local

and added the following line before exit0

/home/pi/bin/script_auto_run 

what mistake am I doing?


回答1:


Open /etc/profile and put this line at the bottom

sudo python /home/pi/projects/test.py

Source



来源:https://stackoverflow.com/questions/29205616/how-to-run-a-python-programcontaining-tkinter-on-startup

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!