forked from Anuprita579/Investhub
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNotes.py
More file actions
135 lines (113 loc) · 3.94 KB
/
Copy pathNotes.py
File metadata and controls
135 lines (113 loc) · 3.94 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
from tkinter import *
from tkinter import filedialog
root = Tk()
root.title("Notes")
root.geometry("900x700")
f1 = Frame(root)
f1.pack()
text_scroll = Scrollbar(f1)
text_scroll.pack(side=RIGHT, fill=Y)
my_text = Text(f1, width=100, height=29, font=("Comic Sans MS", 12), selectbackground="light blue", selectforeground="black", undo=True, yscrollcommand=text_scroll.set)
my_text.pack()
text_scroll.config(command=my_text.yview)
my_menu = Menu(root)
root.config(menu=my_menu)
global open_status_name
open_status_name = False
global selected
selected = False
def new_file():
my_text.delete("1.0", END)
root.title("New File")
statusbar.config(text="New File")
global open_status_name
open_status_name = False
def open_file():
my_text.delete("1.0", END)
text_file = filedialog.askopenfilename(initialdir="C:/gui/", title="Open File", filetypes=(("Text Files", "*.txt"), ("All Files", "*.*")))
if text_file:
global open_status_name
open_status_name = text_file
name = text_file
statusbar.config(text=f'{name}')
name = name.replace("C:/Users/User/Downloads/", "")
root.title(f'{name}')
# Open
text_file = open(text_file, "r")
stuff = text_file.read()
my_text.insert(END, stuff)
text_file.close()
def saveas_file():
text_file = filedialog.asksaveasfilename(defaultextension=".txt", initialdir="C:/gui/", title="Save File", filetypes=(("Text Files", "*.txt"), ("All Files", "*.*")))
if text_file:
global open_status_name
open_status_name = text_file
name = text_file
statusbar.config(text=f'{name}')
name = name.replace("C:/Users/User/Downloads/", "")
root.title(f'{name}')
# save
text_file = open(text_file, "w")
text_file.write(my_text.get(1.0, END))
text_file.close()
def save_file():
global open_status_name
if open_status_name:
text_file = open(open_status_name, "w")
text_file.write(my_text.get(1.0, END))
text_file.close()
statusbar.config(text=f'Saved : {open_status_name}')
else:
saveas_file()
# File Menu
file_menu = Menu(my_menu, tearoff=False)
my_menu.add_cascade(label="File", menu=file_menu)
file_menu.add_command(label="New", command=new_file)
file_menu.add_command(label="Open", command=open_file)
file_menu.add_command(label="Save", command=save_file)
file_menu.add_command(label="Save As", command=saveas_file)
file_menu.add_separator()
file_menu.add_command(label="Exit", command=root.quit)
def cut_text(e):
global selected
if e:
selected = my_text.selection_get()
else:
if my_text.selection_get():
# Select Text
selected = my_text.selection_get()
# Cut Text
my_text.delete("sel.first", "sel.last")
root.clipboard_clear()
root.clipboard_append(selected)
def copy_text(e):
global selected
if e:
selected = root.clipboard_get()
else:
if my_text.selection_get():
# Select Text
selected = my_text.selection_get()
root.clipboard_clear()
root.clipboard_append(selected)
def paste_text(e):
global selected
if e:
selected = root.clipboard_get()
else:
if selected:
position = my_text.index(INSERT)
my_text.insert(position, selected)
# Edit Menu
edit_menu = Menu(my_menu, tearoff=False)
my_menu.add_cascade(label="Edit", menu=edit_menu)
edit_menu.add_command(label="Cut ctrl+x", command=lambda : cut_text(False))
edit_menu.add_command(label="Copy ctrl+c", command=lambda : copy_text(False))
edit_menu.add_command(label="Paste ctrl+v", command=lambda : paste_text(False))
statusbar = Label(root, text="Ready", anchor=E)
statusbar.pack(fill=X, side=BOTTOM, ipady=5)
# Edit Bindings
root.bind("<Control-Key-x>", cut_text)
root.bind("<Control-Key-c>", copy_text)
root.bind("<Control-Key-v>", paste_text)
root.mainloop()