1

I need a python script to run at startup so that when the Raspberry Pi powers up a script starts. The script has a Tk window and canvas with a background image that fills a 16:9 display. There are shapes drawn on the canvas over the backgroound.

I have successfully created this part of the project. It is a dashboard display with blinker arrows that blink in sync with LEDs connected to the GPIO pins and triggered by Buttons. I am using gpiozero for the buttons and leds and tkinter for the graphics. When I run it from the IDE it all works great.

All images, shapes, buttons, LEDs, window, canvas, and functions are defined properly.

Here is a function for the left blinker:

def left_blinker():
    global left_arrow

    if not left_LED.value:
        left_LED.on()

    elif left_LED.value:
        left_LED.off()

    if c.itemcget(left_arrow, "fill") == "black":
        left_arrow = c.create_polygon(coords, bg="green")

    elif c.itemcget(left_arrow, "fill") == "green":
        left_arrow = c.create_polygon(coords, bg="black")

    if left_button.value:
        w.after(300 if left_led.value else 700, left_blinker)

All of it works perfectly when I run it from the IDE. It fills the screen with the background image centered and the polygons (arrows) properly placed on the GUI and blinking in sync when the button is held down and stopping when the button is let go. The python script works as expected.

When I start the file from rc.local so it will autorun on powerup with no tkinter window it works - blinkers, LEDs and all. But, when I add even a single

w = Tk()

it will not autorun at all. This script ends with

w.mainloop()

Here is the entry in rc.local:

python3 /home/pi/BMW_LR_lights &

exit 0

Even a test script with ONLY a Tjk window will not run from rc.local. Everything else runs well as ling as there are no tkinter objects.

KenS
  • 31
  • 4

0 Answers0