Pygame, Input Events, and Window Focus

A place to discuss the implementation and style of computer programs.

Moderators: phlip, Moderators General, Prelates

Posts: 1
Joined: Thu Aug 07, 2014 8:30 pm UTC

Pygame, Input Events, and Window Focus

Postby Mudo146 » Thu Aug 07, 2014 8:51 pm UTC

I'm trying to use a Raspi to take a picture (a little jury-rigged thing using a touch screen) and I wish to have a preview come up and then be able to tap the screen to take a picture. I'm using Pygame to write this code, but Pygame can't seem to register the button presses because the preview window is over the pygame window, dragging it out of focus. I could use any and all help.

Here's one of my many attempts at this code. Some of this is cobbled together from different areas of the internet due to my failure to get this to work properly.

Code: Select all

import picamera
from time import sleep
import pygame
import datetime
import string
import random
from datetime import datetime

#Initialize camera
camera = picamera.PiCamera()
camera.brightness = 60

#Initialize pygame and screen
screen = pygame.display.set_mode((1024, 768))
screen = pygame.display.set_mode((1024, 768), FULLSCREEN)

#Begin listening for Events
ev = pygame.event.get()

#Button Press Event
while True:
    for event in ev:
        if event.type == pygame.MOUSEBUTTONUP:
            now =
            size = 10
            allowed = string.ascii_letters
            randomstring = ' ' .join([allowed[random.randint(0, len(allowed) - 1)] for x in xrange(size)])
            camera.capture('/home/pi/pictures/' + ' "%s-%s-%s" ' %(now.year, now.month, + randomstring + '.jpg')
        if event.type == QUIT: sys.exit()
        if event.type == KEYDOWN and event.dict['key'] == 50:
            print 'break'
Last edited by phlip on Sat Aug 09, 2014 4:41 am UTC, edited 1 time in total.
Reason: Add [code] tags

Return to “Coding”

Who is online

Users browsing this forum: No registered users and 8 guests