Skip to content

Commit 0f9bab8

Browse files
authored
Merge pull request #22290 from daniilS/tk_toolitem_order
Respect `position` and `group` argument in Tk toolmanager add_toolitem
2 parents 813e5b0 + 81ad185 commit 0f9bab8

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

lib/matplotlib/backends/_backend_tk.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -839,8 +839,14 @@ def _rescale(self):
839839
def add_toolitem(
840840
self, name, group, position, image_file, description, toggle):
841841
frame = self._get_groupframe(group)
842-
button = NavigationToolbar2Tk._Button(self, name, image_file, toggle,
842+
buttons = frame.pack_slaves()
843+
if position >= len(buttons) or position < 0:
844+
before = None
845+
else:
846+
before = buttons[position]
847+
button = NavigationToolbar2Tk._Button(frame, name, image_file, toggle,
843848
lambda: self._button_click(name))
849+
button.pack_configure(before=before)
844850
if description is not None:
845851
ToolTip.createToolTip(button, description)
846852
self._toolitems.setdefault(name, [])
@@ -852,6 +858,7 @@ def _get_groupframe(self, group):
852858
self._add_separator()
853859
frame = tk.Frame(master=self, borderwidth=0)
854860
frame.pack(side=tk.LEFT, fill=tk.Y)
861+
frame._label_font = self._label_font
855862
self._groups[group] = frame
856863
return self._groups[group]
857864

0 commit comments

Comments
 (0)