This is a desktop application in which by clicking the choose file button, i should be able to select the image from desktop,open it and crop it by drawing a rectangle by the mouse and crop it by pressing the "c" key from the keyboard.The cropped picture will appear on a new window. I want to develop a code for this,but after pressing the choose file button, it is asking for the parameters to be passed in the click and crop function in this line"choose_btn=Button(app,text="Choose file",width=12,command=click_and_crop)".
import cv2
import PIL
from PIL import Image
from tkinter import *
from tkinter import filedialog
app=Tk()
refPt = []
cropping = False
a=0
def click_and_crop(event, x, y, flags, param):
    global refPt, cropping, a
    if event == cv2.EVENT_LBUTTONDOWN:
        refPt = [(x, y)]
        cropping = True
    elif event == cv2.EVENT_LBUTTONUP:
        refPt.append((x, y))
        cropping = False
        cv2.rectangle(image, refPt[0], refPt[1], (0, 255, 0), 2)
        cv2.imshow("image", image)
        a=1
hello_text=StringVar()
hello_labeltext=Label(app,text="Hi there!!",font=("bold",30),pady=20,padx=50)
hello_labeltext.grid(row=0,column=0)
welcome_text=StringVar()
welcome_labeltext=Label(app,text=("Welcome to the Gallery"),font=("bold",20),padx=70)
welcome_labeltext.grid(row=1,column=0)
upload_text=StringVar()
upload_labeltext=Label(app,text=("Click on the Upload Button to upload images"),font=("bold",20),padx=70)
upload_labeltext.grid(row=2,column=0)
choose_btn=Button(app,text="Choose file",width=12,command=click_and_crop)
choose_btn.grid(row=3,column=0,pady=20)
app.title("Image Enhancer")
app.geometry("700x350")
if(a!=0):
        file_path=filedialog.askopenfilename()
        image = cv2.imread(file_path)
        clone = image.copy()
        cv2.namedWindow("image")
        cv2.setMouseCallback("image", click_and_crop)
while True:
    cv2.imshow("image", image)
    key = cv2.waitKey(1) & 0xFF
    if key == ord("r"):
        image = clone.copy()
    elif key == ord("c"):
        break
if len(refPt) == 2:
    roi = clone[refPt[0][1]:refPt[1][1], refPt[0][0]:refPt[1][0]]
    cv2.imshow("ROI", roi)
    cv2.waitKey(0)
cv2.destroyAllWindows()
app.mainloop()
