I am trying to create a qr scanner using tkinter and opencv. On pressing QR scan button camara is opened in new frame and giving perfact results. What I want is when button is pressed camara should be opened in same tkinter window and not in new frame
Code:
import tkinter as tk
import cv2
import numpy as np
import pyzbar.pyzbar as pyzbar
window=tk.Tk()
window.title("SCANNER")
window.geometry("500x500")
window.config(background='black')
window.maxsize(500,500)
def scan():
cap = cv2.VideoCapture(0)
font = cv2.FONT_HERSHEY_PLAIN
while True:
_, frame = cap.read()
decodedObjects = pyzbar.decode(frame)
for obj in decodedObjects:
# print("Data", obj.data)
scanned.config(text=obj.data)
cv2.putText(frame, str(obj.data), (50, 50), font, 2,
(255, 0, 0), 3)
cv2.imshow("Frame", frame)
key = cv2.waitKey(1)
if cv2.getWindowProperty('Frame',cv2.WND_PROP_VISIBLE)<1:
break
cv2.destroyAllWindows()
but3 = tk.Button(window,text="SCAN QR CODE", width=30,font=("Ariel Bold",15),bg='blue', command=scan)
but3.place(x=100, y=160)
scanned = tk.Label(window, text="RESULT", width=30, font=("Ariel Bold", 15))
scanned.place(x=100, y=200)
window.mainloop()