@@ -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 =============================
142132def cut ():
143133 text .event_generate ("<<Cut>>" )
@@ -290,9 +280,13 @@ def send_feedback():
290280# ============================= Main Window =============================
291281
292282root = tk .Tk ()
293- root .geometry ('500x500' )
283+ root .geometry ('600x300' )
284+ root .minsize (200 ,100 )
294285root .title ('notepad' )
295286root .iconbitmap ('notepad.ico' )
287+ text = ScrolledText (root ,height = 1000 ,undo = True )
288+ text .pack (fill = tk .BOTH )
289+
296290menubar = Menu (root )
297291
298292file = Menu (menubar ,tearoff = 0 )
@@ -309,7 +303,8 @@ def send_feedback():
309303
310304edit = 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 )
313308edit .add_separator ()
314309edit .add_command (label = "Cut" ,accelerator = "Ctrl+X" ,command = cut )
315310edit .add_command (label = "Copy" ,accelerator = "Ctrl+C" ,command = copy )
@@ -337,18 +332,25 @@ def send_feedback():
337332
338333menubar .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
341353root .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-
352354root .mainloop ()
353355
354- # ========================== End =======================================
356+ # ========================== End =======================================
0 commit comments