Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/351.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 我想在tkinter中制作一个帧数组_Python_Opencv_Tkinter - Fatal编程技术网

Python 我想在tkinter中制作一个帧数组

Python 我想在tkinter中制作一个帧数组,python,opencv,tkinter,Python,Opencv,Tkinter,大家好,我正在做一个关于人脸识别的学校项目,现在我正在尝试在tkinter上做一个窗口,它的每一帧都会显示我数据库中每个人的姓名和照片。 比如: 帧数取决于人数。求你了,我需要 帮我做这个。非常感谢。这就是我到目前为止写的代码: 将tkinter作为tk导入 从tkinter导入ttk 从PIL导入ImageTk,图像 导入操作系统 BASE_DIR=os.path.dirname(os.path.relpath(_文件__)) image\u dir=os.path.join(BASE\u

大家好,我正在做一个关于人脸识别的学校项目,现在我正在尝试在tkinter上做一个窗口,它的每一帧都会显示我数据库中每个人的姓名和照片。 比如:

帧数取决于人数。求你了,我需要 帮我做这个。非常感谢。这就是我到目前为止写的代码:

将tkinter作为tk导入
从tkinter导入ttk
从PIL导入ImageTk,图像
导入操作系统
BASE_DIR=os.path.dirname(os.path.relpath(_文件__))
image\u dir=os.path.join(BASE\u dir,“我的脸”)
类MainUi(tk.tk):
def listDir(目录):
全局名称
全球口述
名称=[]
dict={}
fileNames=os.listdir(dir)
对于文件名中的文件名:
name.append(文件名)
i=0
而我(姓名):
dict[i]=(名称[i])
i=i+1
返回指令
列表目录(图像目录)
def get_名称(自身,cmpt):
self.name=名称[cmpt]
返回self.name
定义初始化(self,*args,**kwargs):
tk.tk.\uuuuu初始化(self,*args,**kwargs)
自几何(“300x400”)
自身几何(“500+100”)
容器=tk.框架(自身)
container.pack(side=“top”,fill=“both”,expand=True)
self.frames={}
帧=起始页(容器,自身)
自帧[起始页]=帧
frame.place(relx=0,rely=0,relwidth=1,relheight=1)
frame2=Page1(容器,自身)
self.frames[Page1]=frames2
frame2.place(relx=0,rely=0,relwidth=1,relheight=1)
数组_帧=[]
frame3=Page1(容器,自身)
自显示帧(起始页)
打印(自帧)
def显示画面(自身,续):
帧=自身帧[续]
frame.tkraise()
类起始页(传统框架):
定义初始化(自、父、控制器):
tk.Frame.\uuuu init\uuuuu(自,父)
self.configure(后台='white')
label=tk.label(self,text=MainUi.get_name(self,0))
标签包装(pady=10,padx=10)
button1=ttk.Button(self,text=“Next”,width=7,command=lambda:controller.show_frame(第1页))
按钮1.位置(relx=0.8,rely=0.45)
img1=Image.open(“C://Users/poste/PycharmProjects/untitled2/photos/Liste_habitats.jpg”)
resized_img1=img1.resize((228,45),Image.ANTIALIAS)
membre1=ImageTk.PhotoImage(已调整大小\u img1)
类别第1页(传统框架):
定义初始化(自、父、控制器):
tk.Frame.\uuuu init\uuuuu(自,父)
self.configure(background='gray')
label=tk.label(self,text=MainUi.get_name(self,2))
标签包装(pady=10,padx=10)
button2=ttk.Button(self,text=“Back”,width=7,command=lambda:controller.show_frame(起始页))
按钮2.位置(relx=0.04,rely=0.45)
button3=ttk.按钮(self,text=“Next”,宽度=7)
按钮3.位置(relx=0.8,RELn=0.45)
app=MainUi()
app.mainloop()

您需要什么样的帮助?一个好问题需要问一些比“我需要帮助”更具体的问题。是什么阻止您创建帧数组?
import tkinter as tk
from tkinter import ttk
from PIL import ImageTk, Image
import os

BASE_DIR = os.path.dirname(os.path.relpath(__file__))
image_dir = os.path.join(BASE_DIR, "my_training_face")

class MainUi(tk.Tk):
    def listDir(dir):
        global names
        global dict
        names = []
        dict = {}
        fileNames = os.listdir(dir)
        for fileName in fileNames:
            names.append(fileName)
        i = 0
        while i < len(names):
            dict[i] = (names[i])
            i = i + 1
        return dict

    listDir(image_dir)

    def get_name(self, cmpt):
        self.name = names[cmpt]
        return self.name


    def __init__(self, *args, **kwargs):
        tk.Tk.__init__(self, *args, **kwargs)
        self.geometry("300x400")
        self.geometry("+500+100")
        container = tk.Frame(self)
        container.pack(side="top", fill="both", expand=True)

        self.frames = {}
        frame = StartPage(container, self)
        self.frames[StartPage] = frame
        frame.place(relx=0, rely=0, relwidth=1, relheight=1)

        frame2 = Page1(container, self)
        self.frames[Page1] = frame2
        frame2.place(relx=0, rely=0, relwidth=1, relheight=1)

        array_frames=[]
        frame3= Page1(container,self)

        self.show_frame(StartPage)

        print(self.frames)


    def show_frame(self, cont):
        frame = self.frames[cont]
        frame.tkraise()



class StartPage(tk.Frame):
    def __init__(self, parent, controller):
        tk.Frame.__init__(self, parent)
        self.configure(background='white')
        label = tk.Label(self, text=MainUi.get_name(self,0))
        label.pack(pady=10, padx=10)

        button1 = ttk.Button(self, text="Next", width=7, command = lambda: controller.show_frame(Page1))
        button1.place(relx=0.8, rely=0.45)

        img1 = Image.open("C://Users/poste/PycharmProjects/untitled2/photos/Liste_habitants.jpg")
        resized_img1 = img1.resize((228, 45), Image.ANTIALIAS)
        membre1 = ImageTk.PhotoImage(resized_img1)

class Page1(tk.Frame):
    def __init__(self,parent, controller):

        tk.Frame.__init__(self, parent)
        self.configure(background='gray')
        label = tk.Label(self, text=MainUi.get_name(self,2))
        label.pack(pady=10, padx=10)
        button2 = ttk.Button(self, text="Back ", width=7, command = lambda : controller.show_frame(StartPage))
        button2.place(relx=0.04, rely=0.45)
        button3 = ttk.Button(self, text="Next", width=7)
        button3.place(relx=0.8, rely=0.45)

app = MainUi()
app.mainloop()