-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
49 lines (38 loc) · 1.45 KB
/
app.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
import tkinter as tk
import PyPDF2
from PIL import Image, ImageTk
from tkinter.filedialog import askopenfile
root = tk.Tk()
canvas = tk.Canvas(root, width=600, height=300)
canvas.grid(columnspan=3, rowspan=3)
#logo
logo = Image.open('logo.png')
logo = ImageTk.PhotoImage(logo)
logo_label = tk.Label(image=logo)
logo_label.image = logo
logo_label.grid(column=1, row=0)
#instructions
instructions = tk.Label(root, text="Select a PDF file on your computer to extract all its text", font="Serif")
instructions.grid(columnspan=3, column=0, row=1)
def open_file():
browse_text.set("loading...")
file = askopenfile(parent=root, mode='rb', title="Choose a file", filetypes=[('Pdf file', '*.pdf')])
if file:
read_pdf = PyPDF2.PdfReader(file)
page = read_pdf.pages[0]
page_content = page.extract_text()
#text box
text_box = tk.Text(root, height=10, width=50, padx=15, pady=15)
text_box.insert(1.0, page_content)
text_box.tag_configure("center", justify="center")
text_box.tag_add("center", 1.0, "end")
text_box.grid(column=1, row=3)
browse_text.set("Browse")
#browse button
browse_text = tk.StringVar()
browse_btn = tk.Button(root, textvariable=browse_text, command=lambda: open_file(), font="Serif", bg="#20bebe", fg="white", height=2, width=15)
browse_text.set("Browse")
browse_btn.grid(column=1, row=2)
canvas = tk.Canvas(root, width=600, height=250)
canvas.grid(columnspan=3)
root.mainloop()