1
我是'Python世界'中的新人,我(试图)为我的孩子们制作相机。 我买了一个picamera并为它写了一个python脚本。用相机预览的Pi相机预览 - 树莓派
python脚本很简单(就像picam的例子): 打开picamera,显示预览窗口,睡5秒钟并拍照。
好......到现在为止,没有什么大不了的......
,但是当我试图把预览窗口中的Tkinter窗口的前面,不行! 我知道这是不可能把picamera预览图像放到tkinter框架中,但我们可以用预览窗口来伪装它。 但每次运行该程序时,相机都会显示5秒钟,拍摄照片,之后tkinter会生成窗口。
我试图子,但什么都没有改变,这里的代码(在相机文件):
这里是代码: 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()