Python 带GUI的Pi摄像头预览-覆盆子Pi
我是“Python世界”的新手,我正在(试图)为我的孩子们制作一个摄影棚。 我买了一个picamera并为它编写了一个python脚本 python脚本很简单(就像picam的示例): 打开picamera,显示预览窗口,睡眠5秒钟,然后拍照 嗯。。。直到现在,没什么大不了的 但是,当我尝试将预览窗口放在tkinter窗口的前面时,它不起作用! 我知道不可能将picamera预览图像放在tkinter帧上,但我们可以用预览窗口来伪造它。 但每次我运行程序时,相机都会出现5秒钟,然后拍照,然后tkinter就会创建窗口 我正在尝试子流程,但没有任何更改,下面是代码(在相机文件中): 代码如下: cam.py: gui.py:Python 带GUI的Pi摄像头预览-覆盆子Pi,python,user-interface,python-3.x,camera,subprocess,Python,User Interface,Python 3.x,Camera,Subprocess,我是“Python世界”的新手,我正在(试图)为我的孩子们制作一个摄影棚。 我买了一个picamera并为它编写了一个python脚本 python脚本很简单(就像picam的示例): 打开picamera,显示预览窗口,睡眠5秒钟,然后拍照 嗯。。。直到现在,没什么大不了的 但是,当我尝试将预览窗口放在tkinter窗口的前面时,它不起作用! 我知道不可能将picamera预览图像放在tkinter帧上,但我们可以用预览窗口来伪造它。 但每次我运行程序时,相机都会出现5秒钟,然后拍照,然后tk
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()
丹尼尔!问题出现在gui.py的最后一行之前,因为当您使用communicate()方法时,它会等待进程终止,因此预览正在运行或gui正在运行
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()