1

I am having a hard time figuring out how to close one picture and then open the next. Right now it will close feh if it is already open and then I can click a button and it will open the picture. After a picture button is pressed the kill feh button no longer works. Tried doing an echo statement and it will not work after another button is pressed either.

Here is what I have so far.


#!/bin/python
# a simple script for using the tactile buttons on the TFT

import RPi.GPIO as GPIO
import time
import os
os.putenv('DISPLAY', ':0')

# Use Broadcom SOC Pin Numbers
# setup with internal pullups and pin in READ mode

GPIO.setmode(GPIO.BCM)
#GPIO.setmode(GPIO.BOARD)
GPIO.setup(22, GPIO.IN, pull_up_down = GPIO.PUD_UP)
GPIO.setup(27, GPIO.IN, pull_up_down = GPIO.PUD_UP)
GPIO.setup(21, GPIO.IN, pull_up_down = GPIO.PUD_UP)
#GPIO.setup(18, GPIO.IN, pull_up_down = GPIO.PUD_UP)

#  Main Loop

while True:
    if ( GPIO.input(21) == False ):
        os.system("/home/pi/feh-3.7.2/src/feh -Y -x -q -D 5 -B black -F -Z -r /home/pi/Desktop/media/DSC00605.JPG")
        quit()
    if ( GPIO.input(27) == False ):
        os.system("pkill feh")
        time.sleep(1)
    elif( GPIO.input(22) == False ):
        os.system("/home/pi/feh-3.7.2/src/feh -Y -x -q -D 5 -B black -F -Z -r /home/pi/Desktop/media/DSC00604.JPG")
        time.sleep(1)
  • I dunno why you are using Python to program in shell... the rule of thumb is never use `system()` syscall for anything more than a very simple commands result of which you don’t use explicitly. – 0andriy Dec 15 '21 at 23:41
  • Check on how syscall `fork()` works. – 0andriy Dec 15 '21 at 23:43

0 Answers0