Anup Sarkar Anup Sarkar - 5 months ago 69
Linux Question

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

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?

Answer

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

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

Source

Comments