-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathessay_to_scripts.py
More file actions
84 lines (66 loc) · 1.61 KB
/
essay_to_scripts.py
File metadata and controls
84 lines (66 loc) · 1.61 KB
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
from tkinter import *
import customtkinter as ck
import re
from tkinter import filedialog
#### Variables ##
title_txt = 'Scripts Converter'
win_size = '640x480'
label_txt = 'Label Text'
button_txt = 'Convert'
switch_txt = 'Switch text'
switch_output_txt = 'The output is already changed.'
pattern = "[.,?!;:]"
# pattern = r"\W"
rep = r"\n"
### click event ###
def convert():
result = re.sub(pattern, rep, input_txt.get(1.0, END))
# update_result = src_txt.set(f'{result}')
output_txt.delete('1.0', "end")
# print(output_txt.insert(END, result))
output_txt.insert(END,result)
def save_file():
result = re.sub(pattern, rep, input_txt.get(1.0, END))
file = filedialog.asksaveasfilename(
filetypes=[('text file', '*.txt'), ('CSV file', '*.csv')],
defaultextension= '.txt',
#initialdir = r'D:/',
title = 'Save As'
)
fob = open(file,'w')
fob.write(f"{result}")
fob.close()
#### Elements ##
root = ck.CTk()
root.title(title_txt)
root.geometry(win_size)
src_txt = StringVar()
input_txt = Text(
master=root,
height=10,
width=80
)
button1 = ck.CTkButton(
master = root,
command= convert,
text = button_txt
)
button2 = ck.CTkButton(
master = root,
command = lambda: input_txt.delete(1.0, END),
text = 'Clear'
)
button3 = ck.CTkButton(
master = root,
command = save_file
,
text = 'Export To File'
)
output_txt = Text(root)
### layout ###
button1.grid(row=0,column=0)
button2.grid(row=0,column=1)
button3.grid(row=0,column=2)
input_txt.grid(row=1, columnspan=3)
output_txt.grid(row=2, columnspan=3)
root.mainloop()