Reputation: 122
i am new in the 'Python world' and i am (trying to) make a photobooth for my kids. i bought a picamera and wrote a python script for it.
the python script it's simple (like the examples of the picam): open the picamera, show the preview window, sleep for 5 seconds and take the picture.
well... until now, not big deal...
but when i try to put the preview window in the front of the tkinter window, doesn't work! i know that it's not possible put picamera preview image to the tkinter frame, but we can fake it with preview window. but every time that i run the program, the camera shows up for 5 seconds, take the picture and just after that the tkinter builds the window.
i am trying subprocess but nothing changed, here's the code (in the camera file):
here is the code: cam.py:
import picamera
from time import sleep
with picamera.PiCamera() as camera:
camera.preview_fullscreen=False
camera.preview_window=(620, 320, 640, 480)
camera.resolution=(640,480)
camera.start_preview()
camera.sharpness = 10
camera.contrast = 30
camera.vflip=False
camera.hflip=False
camera.exposure_mode = 'auto'
sleep(10)
#camera.stop_preview()
#camera.close()
gui.py:
from Tkinter import *
import RPi.GPIO as GPIO
import Image
from PIL import Image, ImageTk
from subprocess import Popen, PIPE
class Tela(object):
def __init__(self,master, **kwargs):
self.master=master
pad=3
self.geom='200x200+0+0'
master.geometry("{0}x{1}+0+0".format(master.winfo_screenwidth()-pad,
master.winfo_screenheight()-pad))
def toggle_geom(self, event):
geom=self.master.winfo_geometry()
print(geom,self._geom)
self.master.geometry(self._geom)
self._geom=geom
win = Tk()
win.title("test")
app=Tela(win)
frame = Frame(win)
frame.pack()
proc=Popen(["python","cam.py"],stdout=PIPE)
output=proc.communicate()[0]
print output
win.mainloop()
Upvotes: 2
Views: 17797
Reputation: 36
Daniel! the problem is in the line before your last line of gui.py because when you use the method communicate() it wait for process to terminate so either the preview is running or the gui is running.
Upvotes: 2