Skip to content

Backport PR #22290 on branch v3.5.x (Respect position and group argument in Tk toolmanager add_toolitem) #22321

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion lib/matplotlib/backends/_backend_tk.py
Original file line number Diff line number Diff line change
Expand Up @@ -824,8 +824,14 @@ def _rescale(self):
def add_toolitem(
self, name, group, position, image_file, description, toggle):
frame = self._get_groupframe(group)
button = NavigationToolbar2Tk._Button(self, name, image_file, toggle,
buttons = frame.pack_slaves()
if position >= len(buttons) or position < 0:
before = None
else:
before = buttons[position]
button = NavigationToolbar2Tk._Button(frame, name, image_file, toggle,
lambda: self._button_click(name))
button.pack_configure(before=before)
if description is not None:
ToolTip.createToolTip(button, description)
self._toolitems.setdefault(name, [])
Expand All @@ -837,6 +843,7 @@ def _get_groupframe(self, group):
self._add_separator()
frame = tk.Frame(master=self, borderwidth=0)
frame.pack(side=tk.LEFT, fill=tk.Y)
frame._label_font = self._label_font
self._groups[group] = frame
return self._groups[group]

Expand Down