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()

 

If you are Happy with DataFlair, do not forget to make us happy with your positive feedback on Google

courses

TechVidvan Team

TechVidvan Team provides high-quality content & courses on AI, ML, Data Science, Data Engineering, Data Analytics, programming, Python, DSA, Android, Flutter, full stack web dev, MERN, and many latest technology.

Leave a Reply

Your email address will not be published. Required fields are marked *