0

Hey I have gotten a simple tkinter window to display my webcam using OpenCv from this question, see code

However, when I try to resize the window using my mouse curser, does the window go black and gets unresponsive. How do I fix this, so I can resize the window after I have started the application?

Update

After a comment from @jizhihaoSAMA have I discovered that this bug is only affecting my mac running macOS 10.15.4 and python 3.7. However, it does not affect my windows 10 PC running python 3.7.

import tkinter as tk
import cv2
from PIL import Image, ImageTk

width, height = 800, 600
cap = cv2.VideoCapture(0)
cap.set(cv2.CAP_PROP_FRAME_WIDTH, width)
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, height)

root = tk.Tk()
root.bind('<Escape>', lambda e: root.quit())
lmain = tk.Label(root)
lmain.pack()


def show_frame():
    _, frame = cap.read()
    frame = cv2.flip(frame, 1)
    cv2image = cv2.cvtColor(frame, cv2.COLOR_BGR2RGBA)
    img = Image.fromarray(cv2image)
    imgtk = ImageTk.PhotoImage(image=img)
    lmain.imgtk = imgtk
    lmain.configure(image=imgtk)
    lmain.after(10, show_frame)


show_frame()
root.mainloop()

0 Answers0