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

Skip to content

Commit 8fa8204

Browse files
deselect buttons that are not the current _Mode
1 parent f7ae157 commit 8fa8204

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

lib/matplotlib/backends/_backend_tk.py

Lines changed: 17 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,22 @@ 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+
# Tk Checkbuttons only need to be switched off manually
550+
# if mode was changed by some other button
551+
for text, mode in [('Zoom', _Mode.ZOOM), ('Pan', _Mode.PAN)]:
552+
if self.mode != mode:
553+
self._buttons[text].deselect()
554+
555+
def pan(self, *args):
556+
super().pan(*args)
557+
self._update_buttons_checked()
558+
559+
def zoom(self, *args):
560+
super().zoom(*args)
561+
self._update_buttons_checked()
562+
547563
def set_message(self, s):
548564
self.message.set(s)
549565

0 commit comments

Comments
 (0)