为什么我的Tkinter窗口不显示我的面板?

时间:2019-10-17 19:48:35

标签: python python-3.x opencv tkinter

我有以下代码:

import tkinter
import cv2
from PIL import Image, ImageTk
import threading


class HudGui:
    def __init__(self, window):
        # defining everything for video capture and the tkinter window
    self.CapDev= cv2.VideoCapture(0)
    self.cams = []
    self.counter = 0
    self.frame = None
    self.panel = None
    self.wind = window

    btn = tkinter.Button(window, text="Snapshot!")
    btn.pack(side="bottom", fill="both", expand="yes", padx=10, pady=10)

    # defining threading for video stream
    self.stopEvent = threading.Event()
    self.thread = threading.Thread(target=self.videoLoop(), args=(1,))
    self.thread.start()

def videoLoop(self):
    while not self.stopEvent.is_set():

        # reading and modifying the frame to have the proper data type
        self.frame = self.CapDev.read()[1]
        image = cv2.cvtColor(self.frame, cv2.COLOR_BGR2RGB)
        image = Image.fromarray(image)
        image = ImageTk.PhotoImage(image)

        if self.panel is None:
            self.panel = tkinter.Label(image=image)
            self.panel.image = image
            self.panel.pack(side="left")   # side="left", padx=10, pady=10

            # otherwise, update the panel
        else:
            self.panel.configure(image=image)
            self.panel.image = image


hud = tkinter.Tk()
hud.title("HUD")

HudGui(hud)

hud.mainloop()

当我运行这段代码时,什么都没有发生。我没有窗口,但是我知道它正在更新面板(我已经用打印消息对其进行了测试)。进入摄像头之类的权限可能存在问题吗?

项目信息:

Python = 3.7.3

opencv-contrib-python = 3.4.4.19

0 个答案:

没有答案