I have created a weather forecast display application using Python and tkinter for Raspberry pi zero. The app pulls the weather from a weather api using requests and displays the forecast using images and labels. I run the app using python3 ./myappname.py
and everything works fine.
I want this app to display automatically every time Raspberry Pi restarts. So I am writing a bash script that starts the application. The next step is to run the bash script on startup using cron or autostart. I have created a script with this code:
/bin/sleep 10 && /usr/bin/python3 /home/pi/myappname.py
I am running it using sh myscript
When I run this script, the app loads but there are no images or labels on the page, its a blank white screen. There are no error messages.
What could be causing the app to render fine when I directly run it but blank white screen when running with a script?
Most probably your script is loading images in relative path.
python ./myappname.py
indicates that the current directory is the directory where the script is, so it works.
However the current directory may not be the python script directory when running the bash script at startup.
You need to change directory to the python script directory before running the python script inside the bash script:
#!/bin/bash
cd /home/hi
/bin/sleep 10
/usr/bin/python myappname.py