Работа над проектом фотобудки с использованием Raspberry Pi и Python.В настоящее время кодируем графический интерфейс, и когда я вызываю обратный отсчет, программа делает три снимка перед запуском, несмотря на то, что я вызывал обратный отсчет () перед захватом снимков.
#import statements
import tkinter
import picamera
import time
from picamera import PiCamera
from tkinter import *
#Setup proper rotation and dimensions for live camera preview
camera = PiCamera()
camera.rotation = 270
camera.start_preview()
camera.preview_fullscreen = False
camera.preview_window = (420, 120, 380, 300)
counter = 0
def countdown(count):
# change text in label
textbox['text'] = count
if count > 1:
# call countdown again after 1000ms (1s)
top.after(1000, countdown, count-1)
#configures the gui window
top = tkinter.Tk()
#sets background color to green
top.configure(background = 'green')
#configures dimensions for window
top.geometry('800x480+0+0')
textbox = tkinter.Label(top, bg = "green", fg = "white", font = ('Comic Sans MS', 15))
textbox.pack()
textbox.place(x=187, y=125)
#defines the command to take multiple pictures
def takePicture():
#sets up variables for loop
counter = 0
number = 0
#sets up loop to take 3 pictures
while counter < 3:
countdown(4)
#Sets up camera and saves a picture to the destination
camera.resolution = (1280, 720)
camera.capture("/home/pi/Desktop/Image" + str(number) + ".jpg")
#Adds to the variable to keep loop running until 3 pictures are taken
counter += 1
number += 1
#configures the button text, command, and font
B = tkinter.Button(top, text ="Take Photo!", command = takePicture, font = ('Comic Sans MS',15), bg = 'white', fg = 'green')
#allows the button to work
B.pack()
#configures the positioning and dimensions of the button
B.place(x=150, y=185, width=125, height=75)
#loops the GUI window so it doesn't close
top.mainloop()
#stops camera preview
camera.stop_preview()