-
Notifications
You must be signed in to change notification settings - Fork 5
/
imageGUI.py
59 lines (44 loc) · 1.67 KB
/
imageGUI.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
from tkinter import *
from tkinter import ttk
from tkinter.filedialog import askopenfilename
from PIL import Image
import pytesseract
root = Tk( )
def readFimage():
path = PathTextBox.get('1.0','end-1c')
if path:
im = Image.open(path)
text = pytesseract.image_to_string(im, lang = 'eng')
ResultTextBox.delete('1.0',END)
ResultTextBox.insert(END,text)
else:
ResultTextBox.delete('1.0',END)
ResultTextBox.insert(END,"FILE CANNOT BE READ")
def OpenFile():
name = askopenfilename(initialdir="/",
filetypes =(("PNG File", "*.png"),("BMP File", "*.bmp"),("JPEG File", "*.jpeg")),
title = "Choose a file."
)
PathTextBox.delete("1.0",END)
PathTextBox.insert(END,name)
Title = root.title( "Image Reader!")
path = StringVar()
HeadLabel1 = Label(root,text="Image ")
HeadLabel1.grid(row = 1,column = 1,sticky=(E))
HeadLabel2 = Label(root,text=" Reader")
HeadLabel2.grid(row = 1,column = 2,sticky=(W))
InputLabel = Label(root,text = "INPUT IMAGE:")
InputLabel.grid(row=2,column = 1)
BrowseButton = Button(root,text="Browse",command = OpenFile)
BrowseButton.grid(row=2,column=2)
PathLabel = Label(root,text = "Path:")
PathLabel.grid(row = 3,column=1,sticky=(W))
PathTextBox = Text(root,height = 2)
PathTextBox.grid(row = 4,column = 1,columnspan=2)
ReadButton = Button(root,text="READ FROM IMAGE",command = readFimage)
ReadButton.grid(row = 5,column = 2)
DataLabel = Label(root,text = "DATA IN IMAGE:")
DataLabel.grid(row = 6,column=1,sticky=(W))
ResultTextBox = Text(root,height = 6)
ResultTextBox.grid(row = 7,column = 1,columnspan=2)
root.mainloop()