How to Show/Open Dynamic and Multiple Images in OpenCV using Tkinter
Machine Learning courses with 100+ Real-time projects Start Now!!
Program 1
from tkinter import *
import tkinter.messagebox as msg
import tkinter.filedialog as fd
import cv2
def clickmenu(choice):
if(choice=='open'):
filename = fd.askopenfilename(parent=myroot, title='open file window',
filetypes=(("Image", "*.jpg"), ("All File", "*.*")))
img=cv2.imread(filename)
cv2.imshow('Show Window',img)
# cv2.waitKey(0)
# cv2.destroyAllWindows()
elif(choice=='exit'):
ch = msg.askyesno('Exit', 'Are You sure want to exit')
if(ch==True):
myroot.destroy()
myroot=Tk()
myroot.geometry('600x600')
myroot.title("My Image Application")
menubar=Menu(myroot)
myroot.config(menu=menubar)
myfilemenu=Menu(myroot,tearoff=0)
myfilemenu.add_command(label="Open",command=lambda :clickmenu('open'))
myfilemenu.add_separator()
myfilemenu.add_command(label="Exit",command=lambda :clickmenu('exit'))
menubar.add_cascade(label="File",menu=myfilemenu)
myroot.mainloop()
Your opinion matters
Please write your valuable feedback about DataFlair on Google

