Skip to Content
Tkinter GUI Programming by Example
book

Tkinter GUI Programming by Example

by David Love
April 2018
Beginner content levelBeginner
340 pages
7h 54m
English
Packt Publishing
Content preview from Tkinter GUI Programming by Example

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, ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Tkinter GUI Application Development Blueprints, Second Edition - Second Edition

Tkinter GUI Application Development Blueprints, Second Edition - Second Edition

Bhaskar Chaudhary

Publisher Resources

ISBN: 9781788627481Supplemental Content