O'Reilly logo

Tkinter GUI Programming by Example by David Love

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Adding a context menu to our text editor

Once again we will need to add some code to our __init__ method. Since there will only be one Menu needed for our context menu we can just define this directly instead of making another function. Type this code underneath the previous menu code:

self.right_click_menu = tk.Menu(self, bg="lightgrey", fg="black", tearoff=0)self.right_click_menu.add_command(label='Cut', command=self.edit_cut)self.right_click_menu.add_command(label='Copy', command=self.edit_copy)self.right_click_menu.add_command(label='Paste', command=self.edit_paste)

Another Menu widget is created using the same arguments as all of our cascades. We then add three commands to it—cut, copy, and paste. These will still do nothing at the moment, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required