简体   繁体   中英

Using tkinter buttons to execute another script

I have been writing a few programs for the raspberry pi camera, namely one that just shows the camera output, one that takes a picture and then applies face recognition and so on. I got most of these working but I am having trouble incorporating all these into 1 program.

I have the code written like this.

import cv2
import time
from picamera.array import PiRGBArray
from picamera import PiCamera

camera =PiCamera()
camera.resolution=(320, 240)
camera.framerate=30
rawCapture=PiRGBArray(camera, size=(320, 240))

time.sleep(1)

for frame in camera.capture_continuous(rawCapture, format="bgr" , 
use_video_port=True):

image=frame.array


cv2.imshow("Faces" , image)
key = cv2.waitKey(1)

rawCapture.truncate(0)

I don't know if this is what you mean but you can do it like this:

from tkinter import *
def Script():
    #Insert your script here

button = Button(root, text = "Launch Script", command = Script)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM