-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNotpad.py
More file actions
133 lines (111 loc) · 3.49 KB
/
Notpad.py
File metadata and controls
133 lines (111 loc) · 3.49 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
from tkinter import *
import tkinter.messagebox as tmsg
import webbrowser
import gmail
import os
from tkinter.filedialog import *
# Basic tkinter setup
def openfile():
global file
file = askopenfilename(defaultextension=".txt",
filetypes=[("All Files", "*.*"),
"Text Documents"])
if file == "":
file = None
else:
root.title(f"{os.path.basename(file)} - Hacker pad")
textarea.delete(1.0, END)
f = open(file, "r")
textarea.insert(1.0, f.read())
f.close()
def new():
global file
root.title("Untitled - Hacker pad")
file = None
textarea.delete(1.0, END)
def save():
pass
def saveas():
global file
if file is None:
file = asksaveasfilename(initialfile='Untitled.txt', defaultextension=".txt",
filetypes=[("All Files", "*.*"),
"Text Documents"])
if file == "":
file = None
else:
f = open(file, "w")
f.write(textarea.get(1.0, END))
f.close()
# else:
# f = open(file, "w")
# f.write(textarea.get(1.0, END))
# f.close()
def copy():
textarea.event_generate("<<Copy>>")
def cut():
textarea.event_generate("<<Cut>>")
def paste():
textarea.event_generate("<<Paste>>")
def about():
tmsg.showinfo("Hacker pad", "Hacker pad is a text IDE created by Hacker Hunter on 06/03/2020")
def feed():
webbrowser.open("mail.google.com")
tmsg.showinfo("E-mail", "Send your feedback at princebarnwal69@gmail.com")
root = Tk()
root.title("Hacker pad")
root.geometry("500x400")
root.minsize(400, 300)
# Text area
textarea = Text(root, font="consolas 25 bold")
file = None
textarea.pack(fill=BOTH, expand=True)
# Creating our menubar
menubar = Menu(root)
filemenu = Menu(menubar, tearoff=0)
# To open a new file
filemenu.add_command(label="New Project", command=new)
filemenu.add_separator()
# To open a existing file
filemenu.add_command(label="Open", command=openfile)
filemenu.add_separator()
# To save a file
# filemenu.add_command(label="Save", command=save)
# filemenu.add_separator()
# To save a file as user want
filemenu.add_command(label="Save as", command=saveas)
filemenu.add_separator()
menubar.add_cascade(label="File", menu=filemenu)
root.config(menu=menubar)
# Edit menu
editmenu = Menu(menubar, tearoff=0)
# copy command
editmenu.add_command(label="Copy", command=copy)
editmenu.add_separator()
# Cut command
editmenu.add_command(label="Cut", command=cut)
editmenu.add_separator()
# Paste command
editmenu.add_command(label="Paste", command=paste)
editmenu.add_separator()
menubar.add_cascade(label="Edit", menu=editmenu)
# Editmenu ends
# Help menu
Exit = Menu(menubar, tearoff=0)
Exit.add_command(label="Exit", command=root.destroy)
menubar.add_cascade(label="Exit", menu=Exit)
root.config(menu=menubar)
helpmenu = Menu(menubar, tearoff=0)
# About Hackerpad
helpmenu.add_command(label="About Hackerpad", command=about)
# Send feedback
helpmenu.add_command(label="feedback", command=feed)
helpmenu.add_cascade(label="Help")
menubar.add_cascade(label="Help", menu=helpmenu)
root.config(menu=menubar)
# Scroll bar
scroll = Scrollbar(textarea)
scroll.pack(side=RIGHT, fill=Y)
scroll.config(command=textarea.yview)
textarea.config(yscrollcommand=scroll.set)
root.mainloop()