Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 7503

Python • tkinter not using command in button

$
0
0
#I am trying to create an app that identifies a license plate and currently I have the camera running a screen developed that periodically looks #at the camera image and checks to see if there is a license plate (not finished) but the problem I have currently is the setup button doesn't fire t#he command. I have included the code for review and comment. Any suggestions would be appreciated.


#import tkinter as tt
from tkinter import *
import cv2
from datetime import date
import time as tm
from tkinter import filedialog
from tkinter import messagebox
from PIL import Image,ImageTk
import os
from tkinter.ttk import Combobox
from tkinter.ttk import Progressbar
import openpyxl, xlrd
from openpyxl import Workbook
import pathlib
from easyocr import *
from matplotlib import pyplot as plt

global Etime
global Ctime
global goodcamera

# ****************************************************************************
# *** Opening and setting up Camera
# *** If no camera goodcamera = False
# ****************************************************************************
if os.path.isdir('//dev/v4l/by-id'):
goodcamera=True
camerastring ="index0"
camname=""
with os.scandir('//dev/v4l/by-id') as entries:
for entry in entries:
print(f"Name: {entry.name}")
if camerastring in entry.name:
camname='//dev/v4l/by-id/'+entry.name
print(camname)

cap=cv2.VideoCapture()
cap.open(camname)
else:
print("No Cameras Attached")
goodcamera=False

Ctime=tm.time()
background="#06283D"
framebg="#EDEDED"
framefg="#06283D"

def setup_form():
print("I'm at setupform")

# ********************************************************************************
# *** Setting Up Main Tkinter Screen
# *********************************************************************************
root=Tk()
root.title("Casa Fahey Front Gate")
root.geometry("1200x700+10+10")
root.config(bg=background)
ttime=tm.strftime('%I' + ':' + '%M' + ':' + '%S' + ' ' + '%p')

#top frame
Label(root,text="Front Gate Vehicle Camera",width=1200,height=1,bg="#c36464",fg="#fff",font="arial 29 bold").pack()
clock_label=Label(root,text=ttime,font="arial 25", bg="black",fg="white")
clock_label.place(y=3,x=10)

LicensePlate= StringVar()
OwnersName= StringVar()
Date=StringVar()

today = date.today()
d1= today.strftime("%m/%d/%y")

Date.set(d1)

details=Frame(root,bd=3,bg="grey",width =800,height=394,relief=GROOVE)
details.place(x=10,y=50)

LPN= Label(details,text="License Plate Number:",font ="arial 13",fg=framebg,bg=background).place(x=31,y=10)
license_entry= Entry(details,textvariable=LicensePlate,width=15,font="arial 10")
license_entry.place(x=220,y=10)

OWN=Label(details,text="Owners name:",font="arial 13",fg=framebg,bg=background).place(x=400,y=10)
ownersname_entry = Entry(details,textvariable=OwnersName,width=20,font="arial 10")
ownersname_entry.place(x=530,y=10)

check_button=Button(root,text="Idle",font="arial 20",width=29,bg=background,fg=framebg)
check_button.place(x=735,y=450)

setup_button=Button(root,text="Setup",font="arial 20",width=15,bg=background,fg=framebg, command=setup_form)
setup_button.place(x=935,y=600)

Progress=Progressbar(root,orient=HORIZONTAL,length=462, mode='determinate')
Progress.place(x=735,y=495)

#image
camview=Frame(root,bd=3,bg="black",width=530,height=390,relief=GROOVE)
camview.place(x=730,y=50)
imagelabel=Label(camview, width=530, height=390)
imagelabel.pack()

def configuring():
file=pathlib.Path("Vehicles.xlsx")
if file.exists():
pass
else:
file=Workbook()
sheet=file.active
sheet["A1"]="Owner Name"
sheet["B1"]="License Plate"
sheet["C1"]="State"
sheet["D1"]="Rights"
sheet["E1"]="Start Date"
sheet["F1"]="End Date"
sheet["G1"]="Start Time"
sheet["H1"]="End Time"
sheet["I1"]="Description"
sheet["J1"]="Color"
sheet["K1"]=""
sheet["L1"]=""
file.save("Vehicles.xlsx")


# def plateid():
def PreProcessing():
print("PreProcessing")

def update():
if goodcamera == False:
return
global Ctime
global Etime
ret,camview = cap.read()
if ret:
camview = cv2.resize(camview, (530,390))
img = cv2.cvtColor(camview,cv2.COLOR_BGR2RGB)
img = Image.fromarray(img)
imgtk = ImageTk.PhotoImage(image=img)
imagelabel.imgtk = imgtk
imagelabel.configure(image=imgtk)

Etime=(tm.time()-Ctime)
print("Etime ",end="")
print(Etime)
Progress['value']=((Etime/5)*100)
if (Etime>4.9):
print("checklicense")
check_button.config(text="Checking for License Plate",bg='black',fg='white')
Ctime=tm.time()
img2=cv2.cvtColor(camview,cv2.COLOR_BGR2GRAY)
img2 = Image.fromarray(img2)
imgtk = ImageTk.PhotoImage(image=img2)
imagelabel.imgtk = imgtk
imagelabel.configure(image=imgtk)
PreProcessing()
Progress['value']=100
else:
check_button.config(text="Idle",bg=background,fg=framebg)

clock_label.config(text=tm.strftime('%I' + ':' + '%M' + ':' + '%S' + ' ' + '%p'))
root.after(500,update)

configuring()
update()

root.mainloop()

Statistics: Posted by Trashman1 — Wed Sep 24, 2025 8:34 pm



Viewing all articles
Browse latest Browse all 7503

Trending Articles