-
Notifications
You must be signed in to change notification settings - Fork 1
/
editor.py
74 lines (60 loc) · 2 KB
/
editor.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
import tkinter as tk
from tkinter.constants import END
from tkinter.filedialog import *
def openFile():
print("opening")
global file
file = askopenfilename(
filetypes=[("Text Files", "*.txt"), ("All Files", "*.*")]
)
if not file:
return
text_editor.delete(1.0, tk.END)
with open(file, "r") as ifile:
notes = ifile.read()
text_editor.insert(tk.END, notes)
window.title(file + " - Zorro Editor")
def saveAsFile():
global file
file = asksaveasfilename(
defaultextension="txt",
filetypes=[("Text Files", "*.txt"), ("All Files", "*.*")]
)
if not file:
return
# else:
# print(file)
with open(file, "w") as ofile: # File handling with open() => Opens file
notes = text_editor.get(1.0, tk.END)
ofile.write(notes)
window.title(file + " - Zorro Editor")
def saveFile():
if not file:
return
with open(file, "w") as ofile: # File handling with open() => Opens file
notes = text_editor.get(1.0, tk.END)
ofile.write(notes)
window.title(file + " - Zorro Editor")
print("Saved")
window = tk.Tk() # Initializes Tkinter window
window.title("Zorro Editor") # Gives window a Title
window.rowconfigure(0, minsize=500)
window.columnconfigure(1, minsize=500)
tools = tk.Frame(window)
# tools.grid(row=0, column=0, sticky="ns")
tools.pack(expand=True)
text_editor = tk.Text(window)
# text_editor.grid(row=0, column=1, sticky="nsew")
text_editor.pack()
open_button = tk.Button(tools, text="Open File", command=openFile)
open_button.grid(row=0, column=0, padx=2, pady=3)
# open_button.pack()
saveas_button = tk.Button(tools, text="Save As", command=saveAsFile)
saveas_button.grid(row=0, column=1, padx=2, pady=3)
# saveas_button.pack()
save_button = tk.Button(tools, text="Save", command=saveFile)
save_button.grid(row=0, column=2,padx=2, pady=3)
# save_button.pack()
window.bind("<Control-o>",lambda x:openFile())
window.bind("<Control-s>",lambda x:saveFile())
window.mainloop()