Skip to content

Commit c5b94af

Browse files
Update notepad.py
1 parent 19d1477 commit c5b94af

File tree

1 file changed

+25
-23
lines changed

1 file changed

+25
-23
lines changed

Notepad/notepad.py

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -128,16 +128,6 @@ def exit():
128128
# ======================= Edit Code Starts Here ============================
129129
#=======================================================================================
130130

131-
132-
133-
134-
#=========================== Undo code =============================
135-
def undo():
136-
pass
137-
# Its Challenge for you to give the undo functionality in the notepad
138-
139-
#=========================== End code =====================================
140-
141131
#=========================== Cut code =============================
142132
def cut():
143133
text.event_generate("<<Cut>>")
@@ -290,9 +280,13 @@ def send_feedback():
290280
# ============================= Main Window =============================
291281

292282
root = tk.Tk()
293-
root.geometry('500x500')
283+
root.geometry('600x300')
284+
root.minsize(200,100)
294285
root.title('notepad')
295286
root.iconbitmap('notepad.ico')
287+
text = ScrolledText(root,height=1000,undo=True)
288+
text.pack(fill=tk.BOTH)
289+
296290
menubar = Menu(root)
297291

298292
file = Menu(menubar,tearoff = 0)
@@ -309,7 +303,8 @@ def send_feedback():
309303

310304
edit = Menu(menubar,tearoff = 0)
311305

312-
edit.add_command(label="Undo",accelerator="Ctrl+Z",command=undo)
306+
edit.add_command(label="Undo",accelerator="Ctrl+Z",command=text.edit_undo)
307+
edit.add_command(label="Redo",accelerator="Ctrl+Y",command=text.edit_redo)
313308
edit.add_separator()
314309
edit.add_command(label="Cut",accelerator="Ctrl+X",command=cut)
315310
edit.add_command(label="Copy",accelerator="Ctrl+C",command=copy)
@@ -337,18 +332,25 @@ def send_feedback():
337332

338333
menubar.add_cascade(label="Help",menu=Help)
339334

335+
m = Menu(root, tearoff = 0)
336+
m.add_command(label ="Select All",accelerator="Ctrl+A",command=select_all)
337+
m.add_command(label ="Cut",accelerator="Ctrl+X",command=cut)
338+
m.add_command(label ="Copy",accelerator="Ctrl+C",command=copy)
339+
m.add_command(label ="Paste",accelerator="Ctrl+V",command=paste)
340+
m.add_command(label ="Delete",accelerator="Del",command=delete)
341+
m.add_separator()
342+
m.add_command(label ="Undo",accelerator="Ctrl+Z",command=text.edit_undo)
343+
m.add_command(label ="Redo",accelerator="Ctrl+Z",command=text.edit_redo)
344+
345+
def do_popup(event):
346+
try:
347+
m.tk_popup(event.x_root, event.y_root)
348+
finally:
349+
m.grab_release()
350+
351+
root.bind("<Button-3>", do_popup)
340352

341353
root.config(menu=menubar)
342-
343-
344-
345-
346-
347-
text = ScrolledText(root,width=1000,height=1000)
348-
text.place(x=0,y=0)
349-
350-
351-
352354
root.mainloop()
353355

354-
# ========================== End =======================================
356+
# ========================== End =======================================

0 commit comments

Comments
 (0)