-
Notifications
You must be signed in to change notification settings - Fork 1
/
TextEditor.py
53 lines (42 loc) · 1.32 KB
/
TextEditor.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
import easygui as eg
filetoedit=''
def checkuse():
useprogram = eg.ynbox('Welcome to the text editor made with Python3. Would you like to continue?','Welcome',('Yes','No'))
if useprogram==True:
startwriting()
else:
print('Have a good day!')
exit()
def starteditor(fil=''):
print('Editor started')
if fil=='':
texttowrite=eg.textbox('The file is automatically saved once the ok button is pressed','Editing')
savlocation=eg.filesavebox()
with open(savlocation,'w+') as f:
f.write(texttowrite)
if f.closed:
del f
else:
with open(filetoedit,'r+') as f:
texttowrite=eg.textbox(f'Editing {filetoedit}\nThis file will automatically save once you click the ok button','Editing',f.read())
if f.closed:
del f
with open(filetoedit,'w') as f:
f.write(texttowrite)
if f.closed:
del f
def startwriting():
makenew = eg.ynbox('Do you want to create a new file?',('Yes','No'))
if makenew:
makenewfile()
else:
openfile()
def makenewfile():
starteditor()
def openfile():
global filetoedit
filetoedit=eg.fileopenbox('Pick a file to open')
starteditor(filetoedit)
if __name__=='__main__':
while True:
checkuse()