Professional Documents
Culture Documents
Tao Menu
Tao Menu
import tkinter
from tkinter import Frame, Tk, BOTH, Text, Menu, END
from tkinter.filedialog import Open, SaveAs
import cv2
import numpy as np
class Main(Frame):
def initUI(self):
self.parent.title("Digital Image Processing")
self.pack(fill=BOTH, expand=1)
menubar = Menu(self.parent)
self.parent.config(menu=menubar)
fileMenu = Menu(menubar)
fileMenu.add_command(label="Open", command=self.onOpen)
fileMenu.add_command(label="Save", command=self.onSave)
fileMenu.add_separator()
fileMenu.add_command(label="Exit", command=self.quit)
menubar.add_cascade(label="File", menu=fileMenu)
self.txt = Text(self)
self.txt.pack(fill=BOTH, expand=1)
def onOpen(self):
global ftypes
ftypes = [('Images', '*.jpg *.tif *.bmp *.gif *.png')]
dlg = Open(self, filetypes = ftypes)
fl = dlg.show()
if fl != '':
global imgin
imgin = cv2.imread(fl,cv2.IMREAD_GRAYSCALE)
# imgin = cv2.imread(fl,cv2.IMREAD_COLOR);
cv2.namedWindow("ImageIn", cv2.WINDOW_AUTOSIZE)
cv2.imshow("ImageIn", imgin)
def onSave(self):
dlg = SaveAs(self,filetypes = ftypes);
fl = dlg.show()
if fl != '':
cv2.imwrite(fl,imgout)
root = Tk()
Main(root)
root.geometry("640x480+100+100")
root.mainloop()