I want to build a photo box with a Raspberry Pi 3B + (Raspbian). The Python code works, but the autostart does not work: I've already tried to write the file in crontab, rc.local, bash.rc, a desktop file in autostart. Does not work. The recording of the images works, only the display via the graphical user interface with tkinter you never see.

Here is a small part of my code:

Google translated from

Hallo alle miteinander, ich möchte eine Fotobox mit einer RaspberryPi 3B+ (Raspbian) aufbauen. Der Python Code funktioniert, aber der Autostart funktioniert leider nicht: Ich habe schon versucht die Datei in crontab zu schreiben, rc.local, bash.rc,eine Desktop Datei im autostart. Klappt alles nicht. Die Aufnahme der Bilder klappt, nur die Anzeige über die grafische Benutzeroberfläche mit tkinter sieht man nie.

Hier ein kleiner Ausschnitt meines Codes:

#!/usr/bin/env python3
# coding: utf 8
from picamera import * 
from time import sleep 
from PIL import Image, ImageTk
import PIL.Image
import RPi.GPIO as GPIO
from guizero import *
from tkinter import *

def anzeigen_einzel():
    global window
    window = Tk()
    path = '/home/pi/Schreibtisch/Bild.jpg'
    frame = Frame(window)

    image = PIL.Image.open(path)
    photo = ImageTk.PhotoImage(PIL.Image.open(path))
    label = Label(image=photo)
    label.config(width= 1024, height=600)
    label.image = photo

    window.after(3000, window._root().destroy)


GPIO.setup(40, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)

    if (GPIO.input(40) == True):
  • English, please. – MatsK Jun 18 '18 at 11:13
  • "I've already tried to write the file in crontab, rc.local, bash.rc, a desktop file in autostart" - but you haven't bothered to share this with us. – Milliways Jun 18 '18 at 11:39
  • Those autostart methods you mention do work with vanilla Raspbian. Either you made some changes to the system which you should roll back, or the autostart works but your script fails. – Dmitry Grigoryev Jun 21 '18 at 7:05

This seems to be a problem with the GUI isn't initialized when the script starts. Try to start it with systemd with dependency After=graphical.target:

rpi ~$ sudo systemctl --force --full edit my_python_code.service

In the editor insert these statements, save it and quit the editor:

Description=My Python Code



Then enable the service:

rpi ~$ sudo systemctl enable my_python_code.service


| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.