0

I can't work out how to give the 'Picture' object a attribute 'set' in this code so my code for your_pic.set(lastest_photo) is not working properly. The 3rd line from the bottom defines the Picture, so I'm not sure what I'm missing. Could someone please help.

from picamera import PiCamera
from gpiozero import Button
from time import gmtime, strftime
from overlay_functions import *
from guizero import App, PushButton, Text, Picture

def next_overlay():
    global overlay
    overlay = next(all_overlays)
    preview_overlay(camera, overlay)

def take_picture():
    global output
    output = strftime("/home/pi/allseeingpi/image-%d-%m %H:%M.png", gmtime())
    camera.capture(output)
    camera.stop_preview()
    remove_overlays(camera)
    output_overlay(output, overlay)

    size = 400, 400
    gif_img = Image.open(output)
    gif_img.thumbnail(size, Image.ANTIALIAS)
    gif_img.save(latest_photo, 'gif')

    your_pic.set(latest_photo)

def new_picture():
    camera.start_preview(alpha=128)
    preview_overlay(camera, overlay)

next_overlay_btn = Button(23)
next_overlay_btn.when_pressed = next_overlay
take_pic_btn = Button(25)
take_pic_btn.when_pressed = take_picture

camera = PiCamera()
camera.resolution = (800, 480)
camera.hflip = True

camera.start_preview()

output = ""
latest_photo = '/home/pi/allseeingpi/latest.gif'  

app = App("The All-Seeing Pi", 800, 480)
message = Text(app, "I spotted you!")
your_pic = Picture(app, latest_photo)
new_pic = PushButton(app, new_picture, text="New picture")
app.display()
Georgy
  • 12,464
  • 7
  • 65
  • 73
smaft
  • 1
  • Have you tried `your_pic = Picture(app, image=latest_photo)`? – Timus Sep 28 '20 at 11:11
  • Thank you. Will try – smaft Sep 28 '20 at 20:41
  • No luck, that didn't work. Any other ideas? – smaft Sep 29 '20 at 09:30
  • Do you get any error messages? I've tried the lines from `app = ...` to `your_pic = ...` with an `app.display()` afterwards and it works just fine? – Timus Sep 29 '20 at 10:42
  • Yes it keeps saying your_pic.set(latest_photo) attributeerror-picture-object-has-no-attribute-set I’ve tried tens of different variables over hours/days. Run it through python reader and it says no error but when I hit run on my raspberry pi touchscreen it errors. – smaft Sep 29 '20 at 20:22
  • Then I'm out of my depth, sorry! Hope you find a solution. – Timus Sep 29 '20 at 21:31

0 Answers0