Creating the context/pop-up menu

Let's complete the editor in this final iteration by adding a contextual menu to the editor (refer to 2.12.py in the code bundle), as shown in the following screenshot:

Creating the context/pop-up menu

The menu that pops up on the right-mouse-button click at the location of the mouse cursor is called the context menu or the pop-up menu.

Let's code this feature in the text editor. First define the context menu, as follows:

popup_menu = Menu(content_text) for i in ('cut', 'copy', 'paste', 'undo', 'redo'): cmd = eval(i) popup_menu.add_command(label=i, compound='left', command=cmd) popup_menu.add_separator() popup_menu.add_command(label='Select All', underline=7, ...

Get Tkinter GUI Application Development Blueprints now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.