-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbookshelf.py
31 lines (25 loc) · 1.04 KB
/
bookshelf.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
import PySimpleGUI as Sg
Sg.theme("DarkBlue10")
layout = [[Sg.Text("File name / Path:"),
Sg.InputText(s=20, key="-fileName-"), Sg.FileBrowse("Browse"), Sg.Button("Open"), Sg.Button("Save")],
[Sg.Multiline(default_text='', s=(100, 100), key="-text-", expand_x=True, expand_y=True, pad=(0, 0))]
]
window = Sg.Window("eLer Bookshelf, yet another open source text editor", layout, size=(900, 900), resizable=True)
while True:
event, values = window.read()
if event == "Save":
filename = values["-fileName-"]
text_content = values["-text-"]
if filename:
with open(filename, "w") as arqwrite:
arqwrite.write(text_content)
elif event == "Open":
filename = values["-fileName-"]
values["-text-"] = ""
if filename:
with open(filename, "r") as arqread:
arqsync = arqread.read()
window["-text-"].update(arqsync)
elif event == Sg.WIN_CLOSED:
break
window.close()