Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit bd765e0

Browse files
authored
Merge pull request matplotlib#18395 from richardsheridan/multi-toggle-fix
FIX: deselect buttons that are not the current _Mode
2 parents 99d4976 + 1e15cd4 commit bd765e0

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

lib/matplotlib/backends/_backend_tk.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from matplotlib import backend_tools, cbook, _c_internal_utils
1515
from matplotlib.backend_bases import (
1616
_Backend, FigureCanvasBase, FigureManagerBase, NavigationToolbar2,
17-
StatusbarBase, TimerBase, ToolContainerBase, cursors)
17+
StatusbarBase, TimerBase, ToolContainerBase, cursors, _Mode)
1818
from matplotlib._pylab_helpers import Gcf
1919
from matplotlib.figure import Figure
2020
from matplotlib.widgets import SubplotTool
@@ -544,6 +544,23 @@ def __init__(self, canvas, window, *, pack_toolbar=True):
544544
if pack_toolbar:
545545
self.pack(side=tk.BOTTOM, fill=tk.X)
546546

547+
def _update_buttons_checked(self):
548+
# sync button checkstates to match active mode
549+
for text, mode in [('Zoom', _Mode.ZOOM), ('Pan', _Mode.PAN)]:
550+
if text in self._buttons:
551+
if self.mode == mode:
552+
self._buttons[text].select() # NOT .invoke()
553+
else:
554+
self._buttons[text].deselect()
555+
556+
def pan(self, *args):
557+
super().pan(*args)
558+
self._update_buttons_checked()
559+
560+
def zoom(self, *args):
561+
super().zoom(*args)
562+
self._update_buttons_checked()
563+
547564
def set_message(self, s):
548565
self.message.set(s)
549566

0 commit comments

Comments
 (0)