-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnotepad.py
More file actions
198 lines (176 loc) · 7.21 KB
/
Copy pathnotepad.py
File metadata and controls
198 lines (176 loc) · 7.21 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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
from tkinter import *
from tkinter.ttk import *
import os
from tkinter.font import *
from tkinter import simpledialog
import time
from tkinter.filedialog import asksaveasfilename, askopenfilename
from tkinter.messagebox import showerror, showinfo
def OpenGoogle():
try:
from pywhatkit import search
searchit = simpledialog.askstring(
title="Search", prompt="What do you want to search")
if(str(searchit) != "None" and str(searchit) != "none" and str(searchit) != ""):
search(searchit)
except Exception as e:
showerror("No Internet", "Oops Something went wrong we cannot connect to internet. Please check your internet connection and try again later",e)
def changefont(Desired):
try:
fonts=simpledialog.askstring("font","Which font you want?")
Desired['family']=fonts
except Exception as e:
showinfo("Sorry","The font you want is currently unavaialable please try again later",e)
def Newe(event):
global file
root.title('Untitled -Notepad++')
file = None
TextArea.delete(1.0, END)
def New():
global file
root.title('Untitled -Notepad++')
file = None
TextArea.delete(1.0, END)
def About():
showinfo("About notepad", "Created by Sai Prachodhan Devulapalli and serves purpose of writing something useful in it when we require we open it and see it.")
def clear():
TextArea.delete("1.0", "end-1c")
def Cut():
TextArea.event_generate(("<<Cut>>"))
def Copy():
TextArea.event_generate(("<<Copy>>"))
def Paste():
TextArea.event_generate(("<<Paste>>"))
def Darkmode():
TextArea['bg']='Black'
TextArea['fg']='White'
def Help():
showinfo("Some Basic instructions", " --> Please note that notepad is for your writing purpose and you click on the notepad and write anyting you want.\n\n --> For saving file Click on the File and click on submenu option Save or Save As as you want in the directory you want.")
showinfo("Some Basic instructions", " --> For Turning into Dark mode please click on Format and then choose Dark mode.\n\n --> You can also see there is option to change font and select that for changing font and fontsize and all.")
def Helpe():
showinfo("Some Basic instructions", " --> Please note that notepad is for your writing purpose and you click on the notepad and write anyting you want.\n\n --> For saving file Click on the File and click on submenu option Save or Save As as you want in the directory you want.")
showinfo("Some Basic instructions", " --> For Turning into Dark mode please click on Format and then choose Dark mode.\n\n --> You can also see there is option to change font and select that for changing font and fontsize and all.")
def DateandTime():
time_label = Label(text=str(time.asctime(
time.localtime(time.time()))), font="Arial 19 bold")
time_label.pack(pady=4)
def Opene():
file = askopenfilename(defaultextension=".txt", filetypes=[
("All Files", "*.*"), ("Text Documents", "*.txt")])
if(file == ""):
file = None
else:
root.title(os.path.basename(file)+" -Notepad++")
TextArea.delete(1.0, END)
f = open(file, "r")
TextArea.insert(1.0, f.read())
f.close()
def Open():
file = askopenfilename(defaultextension=".txt", filetypes=[
("All Files", "*.*"), ("Text Documents", "*.txt")])
if(file == ""):
file = None
else:
root.title(os.path.basename(file)+" -Notepad++")
TextArea.delete(1.0, END)
f = open(file, "r")
TextArea.insert(1.0, f.read())
f.close()
def saveFilee(event):
global file
if file == None:
file = asksaveasfilename(initialfile='Untitled.txt', defaultextension=".txt",
filetypes=[("All Files", "*.*"),
("Text Documents", "*.txt")])
if file == "":
file = None
else:
# Save as a new file
f = open(file, "w")
f.write(TextArea.get(1.0, END))
f.close()
root.title(os.path.basename(file) + " - Notepad")
print("File Saved")
else:
# Save the file
f = open(file, "w")
f.write(TextArea.get(1.0, END))
f.close()
def saveFile():
global file
if file == None:
file = asksaveasfilename(initialfile='Untitled.txt', defaultextension=".txt",
filetypes=[("All Files", "*.*"),
("Text Documents", "*.txt")])
if file == "":
file = None
else:
# Save as a new file
f = open(file, "w")
f.write(TextArea.get(1.0, END))
f.close()
root.title(os.path.basename(file) + " - Notepad")
print("File Saved")
else:
# Save the file
f = open(file, "w")
f.write(TextArea.get(1.0, END))
f.close()
root = Tk()
root.geometry("900x450")
root.minsize(500, 400)
Desired=Font(family="lucida",size="13")
# For title and favicon at the top of tkinter window
root.wm_iconbitmap('notepad.ico')
root.title("Untitled -Notepad++")
Mainmenu = Menu(root)
# This is file menu and its submenus
Filesubmenu = Menu(Mainmenu, tearoff=0)
Filesubmenu.add_command(label="New Ctrl+n", command=New)
Filesubmenu.add_command(label="Open Ctrl+o", command=Open)
Filesubmenu.add_separator()
Filesubmenu.add_command(label="Save As Ctrl+s", command=saveFile)
Filesubmenu.add_separator()
Filesubmenu.add_command(label="Exit Ctrl+q", command=quit)
Mainmenu.add_cascade(label="File", menu=Filesubmenu)
# This is for Edit menu and its sub menus
Editmenu = Menu(Mainmenu, tearoff=0)
Editmenu.add_command(label="Cut", command=Cut)
Editmenu.add_command(label="Copy", command=Copy)
Editmenu.add_command(label="Paste", command=Paste)
Editmenu.add_separator()
Editmenu.add_command(label="Replace")
Editmenu.add_command(label="Clear All", command=clear)
Editmenu.add_command(label="Date and time", command=DateandTime)
Mainmenu.add_cascade(label="Edit", menu=Editmenu)
# This is for Format menu and its submenus
Fontmenu = Menu(Mainmenu, tearoff=0)
font = "lucida"
fontsize = "13"
Fontmenu.add_command(label="Change Font",command=lambda: changefont(Desired))
Fontmenu.add_command(label="Turn to dark mode", command=Darkmode)
Mainmenu.add_cascade(label="Format", menu=Fontmenu)
# for adding Help option
Helpmenu = Menu(Mainmenu, tearoff=0)
Helpmenu.add_command(label="About", command=About)
Helpmenu.add_command(label="Ask Google", command=OpenGoogle)
Helpmenu.add_command(label="Help", command=Help)
Mainmenu.add_cascade(label="Help", menu=Helpmenu)
root.config(menu=Mainmenu)
# Add Text area here and fill with default Font style lucida
TextArea = Text(root,bg="White",fg="Black")
file = None
TextArea.pack(expand=True, fill=BOTH)
TextArea.configure(font=Desired)
# Add a scroll bar for Text Area
scroll = Scrollbar(TextArea,cursor="hand1")
scroll.pack(side=RIGHT, fill=Y)
scroll.config(command=TextArea.yview)
TextArea.config(yscrollcommand=scroll.set)
# For taking events on the notepad
root.bind('<Control-q>', quit)
root.bind('<Control-s>', saveFilee)
root.bind('<Control-n>', Newe)
root.bind('<Control-o>', Opene)
root.bind('<Control-h>', Helpe)
root.mainloop()