0

I'm working on a python script with tkinter. Goal how the program should work: 1: enter an ID & click on "Save ID" (-> Folder with name = ID is created) 2: click on "start capturing" (starting a loop in which u can take as many pictures as u want) 3: make pictures using a physical button 4: after finishing making pictures press "capturing finished" (-> pictures will get send to the folder called ID)

After 4 is finished you can start again by entering a new ID.

Here's the code I'm using:

from tkinter import *
import tkinter.font
import sys, os
from gpiozero import LED
from gpiozero import Button as Knopf
import RPi.GPIO as GPIO
from time import sleep
import datetime


running = True

# Pin Setup ############################################
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM) 
beleuchtung = LED(19)
startsignal = LED(20)
status_led = LED(11)
aufnahme = Knopf(21)

GPIO.setup(8, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) 
GPIO.setup(21, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)#capture button

# Funktionen ############################################

# Übertragung der Bilder beginnen # =============
def sendData():
    global running 
    running = False
    patId = e1.get()
    print(patId)
    status_led.blink(on_time=0.25, off_time=0.25, n=None, background=True)
    print("starting...")
    print("Sending...")
    os.system("scp pi@192.168.2.131:/home/pi/Pictures/* /home/pi/Pictures/ID_"+patId+"/")
    print("finished")
    status_led.off()
    
    
    
# Create Folder with ID # =====================    
def setId():
    patId = e1.get()
    os.system("mkdir /home/pi/Pictures/ID_"+patId)
    global running
    running = True
    return patId
    
    
# Aufnahme Funktion (main function) # ===========   
def capture():
    if running:
        status_led.on()
        aufnahme.wait_for_press()
        status_led.off()
        sleep(0.1)
        beleuchtung.on()              #LED on
        sleep(0.1)                         
        startsignal.on()              #Sends capture command to camera
        sleep(2)
        startsignal.off()
        beleuchtung.off()
        sleep(0.2)
        status_led.off()

        win.after(1000, capture)
    



status_led.blink(on_time=1, off_time=1, n=None, background=True)

# Window Setup #########################################
win = Tk()
win.title("cureVision")
win.geometry=("480x320")
myFont = tkinter.font.Font(family ='Helvetica', size = 12, weight = 'bold')

### WIGDETS ###
label = Label(win, text="Patienten ID eingeben...")
label.grid(row=1)

e1 = Entry(win)
e1.grid(row =1, column=1)

Button(win, text='ID bestätigen', command = setId).grid(row=1, column = 2, sticky=W, pady=4)

sendButton = Button(win, text = 'capturing finished' , font = myFont, command = sendData, bg = 'bisque2', height = 2, width = 23)
sendButton.grid(row=3, column=2)

startButton = Button(win, text = 'start capturing' , font = myFont, command = capture, bg = 'bisque2', height = 2, width = 23)
startButton.grid(row=3, column=1)

win.mainloop()

I'm at the point where I can capture as many pictures as I want but i can't click on "capturing finished". Everything else is working fine.

han_tuch
  • 119
  • 1
  • 9
  • Which loop are you talking about, and whats the error? Using `sleep()` freezes the GUI try starting `capture()` on a separate thread – Delrius Euphoria Oct 14 '20 at 14:29
  • Does this answer your question? [Python tkinter time.sleep()](https://stackoverflow.com/questions/30057844/python-tkinter-time-sleep) – Henry Yik Oct 14 '20 at 14:30
  • @CoolCloud i'm talking about the capture function, which restarts itself as long as running = true, unfortunately i can't set running to false because the button i use for it is unclickable – han_tuch Oct 14 '20 at 14:35
  • The `wait_for_press` is a blocking call. The capture function won't continue until that button is pressed which freezes the GUI. You need to remove that. Your `sleep` calls will also cause the GUI to become unresponsive, although for a much shorter time. – scotty3785 Oct 14 '20 at 14:42
  • I know, but the wait_for_press is needed due to the fact that i need to wait until my physical button is pressed. This is not the problem. It's just that my other buttons are not usable – han_tuch Oct 14 '20 at 14:50
  • No, that is precisely the problem. Try read up the dupe and replace those `sleep` calls with `after`. – Henry Yik Oct 14 '20 at 14:54
  • okay i will give it a try thanks a lot – han_tuch Oct 14 '20 at 15:46

0 Answers0