Skip to content

Commit 2fea63e

Browse files
committed
Add context menu in FigureManagerTk
1 parent 2086384 commit 2fea63e

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

lib/matplotlib/backends/_backend_tk.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -646,6 +646,14 @@ def full_screen_toggle(self):
646646
is_fullscreen = bool(self.window.attributes('-fullscreen'))
647647
self.window.attributes('-fullscreen', not is_fullscreen)
648648

649+
def context_menu(self, event, labels=None, actions=None):
650+
if labels is None or actions is None:
651+
return
652+
menu = tk.Menu(self.window, tearoff=0)
653+
for label, action in zip(labels, actions):
654+
menu.add_command(label=label, command=action)
655+
menu.tk_popup(event.guiEvent.x_root, event.guiEvent.y_root)
656+
649657

650658
class NavigationToolbar2Tk(NavigationToolbar2, tk.Frame):
651659
def __init__(self, canvas, window=None, *, pack_toolbar=True):

0 commit comments

Comments
 (0)