相机程序Raspberry Pi错误发生返回self.func(* args)

时间:2015-08-11 00:17:08

标签: python tkinter raspberry-pi

我似乎对此代码有些麻烦。我一直试图编写一个程序,它连接到一个硬按钮,当按下它时,它将使用Raspberry Pi相机拍摄照片并将其显示在屏幕上的Tkinter窗口中,并允许您按下一个软按钮,再次按下硬按钮将显示另一张照片。我使用GPIO 4将按钮挂钩到Raspberry Pi,但硬键和GPIO不是问题,代码是。

char *

第一次按下硬按钮时程序运行正常,并弹出窗口显示相机拍摄的照片。但是,当我按下软按钮时,它会变为按下的位置,但是当我释放鼠标时,它就会保持这样状态。它说没有发生任何错误,但是当我打开命令行来检查错误消息(它被最小化)时,它开始出现故障并且在屏幕上标记命令行的顶部位。但是,当我点击硬按钮时,会弹出第二个Tkinter窗口,但这次只包含按钮,而不是照片。按下硬按钮也没有破坏根部'窗口,但是,此错误消息弹出:

import RPi.GPIO as GPIO
import picamera
import sys
from Tkinter import *
cam = picamera.PiCamera()
button1 = 4
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(button1, GPIO.IN, GPIO.PUD_UP)
def command():
       pict()
       root.destroy()
       rootcreate()
def rootcreate():
       root = Tk()
       button = Button(root, text = 'Press to take another photo.', command = command)
       button.pack(side = BOTTOM)
       pic = PhotoImage(file="/home/pi/aando.gif")
       l = Label(root, image = pic)
       l.pack()
       root.mainloop()
       GPIO.cleanup()
def pict():
       global a
       a = 1
       global button1
       while a == 1:
              if GPIO.input(button1) == False:
                     GPIO.setmode(GPIO.BCM)
                     cam.capture("aando.gif")
                     rootcreate()
pict()
while 1 == 1:
       sys.stdout.flush()

我搜索了Exception in Tkinter callback Traceback (most recent call last): File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 1437, in __call__ return self.func(*args) File "buttoncam.py", line 11, in command pict() File "buttoncam.py", line 31, in pict rootcreate() File "buttoncam.py", line 19, in rootcreate l = Label(root, image = pic) File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 2502, in __init__ Widget.__init__(self, master, 'label', cnf, kw) File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 2001, in __init__ (widgetName, self._w) + extra + self._options(cnf)) TclError: image "pyimage2" doesn't exist ,但我读到的所有内容对我都没有意义。我也试图绕过init函数,但所有这些都是我的头脑。如果有人能帮我找到解决这个问题的方法,那就太好了。

不幸的是,这还没有结束。关闭所有Tkinter窗口后,会弹出以下错误消息:

return self.func(*args)

我不太确定那里发生了什么,因为正如你所看到的,我已经在代码中提前设置了我的引脚编号模式。如果有人知道如何解决这个问题,那将非常有用。

0 个答案:

没有答案