Im trying to develop a GUI to capture images in a new window. In my work i'am trying to pass a directory of the image to be use on future functions, as of now im trying to configure a label to change its text to my image path
import tkinter as tk
from tkinter import *
import cv2
from PIL import Image, ImageTk
from tkinter.filedialog import askopenfilename
import os
from tkinter import messagebox
from pathlib import PosixPath
from numpy import result_type
class CamView():
def __init__(self, parent):
self.parent = parent
self.window = tk.Toplevel(parent)
self.lmain2 = tk.Label(self.window)
self.lmain2.pack()
self.window.protocol("WM_DELETE_WINDOW", self.close)
self.show_frame()
self.multiple()
self.btn2 = tk.Button(self.window,text="Close", command = lambda: self.close())
self.btn2.pack()
def multiple(self):
self.takePicture_button = tk.Button(self.window, text="Capture Signature",command = lambda: [Main.captureImage(self.parent),self.close()])
self.takePicture_button.pack(ipadx=5,ipady=5,pady=5)
def show_frame(self):
imgtk = ImageTk.PhotoImage(image=self.parent.img)
self.lmain2.imgtk = imgtk
self.lmain2.configure(image=imgtk)
def close(self):
self.parent.test_frame = None
self.window.destroy()
root = tk.Tk()
root.bind('<Escape>', lambda e: root.quit())
font_size = 14
window_width = 800
window_height = 400
screen_width = root.winfo_screenwidth()
screen_height = root.winfo_screenheight()
center_x = int(screen_width/2 - window_width / 2)
center_y = int(screen_height/2 - window_height / 2)
root.geometry(f'{window_width}x{window_height}+{center_x}+{center_y}')
frame_dirpath = tk.Frame(root)
frame_dirpath.pack(ipadx=5,ipady=5)
class Main(tk.Frame):
def __init__(self, parent):
self.lmain = tk.Label(parent)
self.lmain.pack()
self.test_frame = None
frame = Frame.__init__(self,parent)
a = Label(text='Verify Signatures:').pack(ipadx=5,ipady=5)
self.c = tk.Label(text = "check").pack(ipadx=5,ipady=5)
b = tk.Button(frame, text='CAMERA', command=self.load_window)
b.pack()
self.image1_path_entry = tk.Entry(frame_dirpath, font=font_size,width=25).pack(ipadx = 5, ipady = 5)
width, height = 800, 600
self.cap = cv2.VideoCapture(0)
self.cap.set(cv2.CAP_PROP_FRAME_WIDTH, width)
self.cap.set(cv2.CAP_PROP_FRAME_HEIGHT, height)
self.do_stuff()
def do_stuff(self):
_, frame = self.cap.read()
frame = cv2.flip(frame, 1)
cv2image = cv2.cvtColor(frame, cv2.COLOR_BGR2RGBA)
self.img = Image.fromarray(cv2image)
if self.test_frame != None:
self.test_frame.show_frame()
self.lmain.after(10, self.do_stuff)
def captureImage(self):
image_to_write = self.cap.read()[1]
filetowrite = "D:/Downloads/c.jpeg"
print(str(filetowrite))
cv2.imwrite(str(filetowrite),image_to_write)
self.c.configure(text = filetowrite)
return
def load_window(self):
if self.test_frame == None:
self.test_frame = CamView(self)
control = Main(root)
root.mainloop()
As on the line self.c = tk.Label(text = "check").pack(ipadx=5,ipady=5) im trying to configure this label to the image path on the function when capturing an image. All i get is object is has no attribute