-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
102 lines (67 loc) · 1.98 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
from tkinter import *
from tkinter import filedialog
from fpdf import FPDF
def openFile():
tf = filedialog.askopenfilename(
initialdir="C:/Users/MainFrame/Desktop/",
title="Open Text file",
filetypes=(("Text Files", "*.txt"),)
)
pathh.insert(END, tf)
tf = open(tf,'r',encoding="utf8") # or tf = open(tf, 'r')
data = tf.read()
txtarea.insert(END, data)
tf.close()
ws = Tk()
ws.title("Txt viewer and converter")
ws.geometry("800x850")
ws['bg']='#3EB489'
txtarea = Text(ws, width=120, height=40)
txtarea.pack(pady=20)
pathh = Entry(ws)
pathh.pack(side=LEFT, expand=True, fill=X, padx=50)
Button(
ws,
text="Open File",
command=openFile
).pack(side=RIGHT, expand=True, fill=X, padx=20)
def conv(file_name):
pdf = FPDF()
# Add a page
pdf.add_page()
# set style and size of font
# that you want in the pdf
pdf.set_font("Arial", size = 15)
fg=str(file_name)+'.txt'
# open the text file in read mode
f = open(fg, "r",encoding='utf-8')
for x in f:
pdf.cell(200, 10, txt = x, ln = 1, align = 'C')
# save the pdf with name .pdf
pdf.output("my.pdf")
def convert_text():
global e
string = e.get()
if bool(string):
conv(string)
ws.title('Name')
e = Entry(ws)
e.pack()
e.focus_set()
b = Button(ws,text='turn to pdf',command=convert_text)
b.pack(side='top')
# def conv(file_name):
# pdf = FPDF()
# # Add a page
# pdf.add_page()
# # set style and size of font
# # that you want in the pdf
# pdf.set_font("Arial", size = 15)
# fg=str(file_name)+'.txt'
# # open the text file in read mode
# f = open(fg, "r",encoding='utf-8')
# for x in f:
# pdf.cell(200, 10, txt = x, ln = 1, align = 'C')
# # save the pdf with name .pdf
# pdf.output("my.pdf")
ws.mainloop()