I modified the script, it works now the way i want it. I just have the question if i could make it more efficient and if there are some useless lines i've written. Keep in mind that this is only a test with 2 buttons, but the final script should have 10 buttons in it. So maybe there is an easier way to do it. This is my script now:
Code: Select all
#!/usr/bin/env python
import pygame
import sys
import time
from pygame.locals import *
import RPi.GPIO as GPIO
GPIO.setwarnings(False)
GPIO.setmode (GPIO.BCM)
# set GPIO output pins
button1 = 17
button2 = 25
GPIO.setup(button1,GPIO.IN)
GPIO.setup(button2,GPIO.IN)
# picture display size
width = 1920
height = 1080
# File names
screen1 = "/media/A2A7-1908/screen1.jpg"
screen2 = "/media/A2A7-1908/screen2.jpg"
windowSurfaceObj = pygame.display.set_mode((width,height),pygame.FULLSCREEN)
pygame.display.set_caption('Window')
while True:
if GPIO.input(button1)== False:
image = pygame.image.load(screen1)
image = pygame.transform.scale(image,(width,height))
windowSurfaceObj.blit(image,(0,0))
pygame.display.update()
if GPIO.input(button2)== False:
image = pygame.image.load(screen2)
image = pygame.transform.scale(image,(width,height))
windowSurfaceObj.blit(image,(0,0))
pygame.display.update()
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()
elif event.type == KEYDOWN:
# press N for normal screen
if event.key == K_n:
windowSurfaceObj = pygame.display.set_mode((width,height))
windowSurfaceObj.blit(image,(0,0))
pygame.display.update()
# press F for fullscreen
if event.key == K_f:
windowSurfaceObj = pygame.display.set_mode((width,height),pygame.FULLSCREEN)
windowSurfaceObj.blit(image,(0,0))
pygame.display.update()
# press X to EXIT
if event.key == K_x:
pygame.quit()
and another question: what does .blit in the last few lines do? do i even need it?
the question from my post before is still actual: which command from pygame do i need to show a video, if the same input as the one for the images is pressed for 3...5 seconds? is this even possible? i just need a little hint which (two?) lines i need to do it, i can implement it myself after.
thank you guys for all your help