@@ -117,7 +117,9 @@ def __init__(self, ax):
117117self .ax = ax
118118self ._cids = []
119119
120- canvas = property (lambda self :self .ax .get_figure (root = True ).canvas )
120+ canvas = property (
121+ lambda self :getattr (self .ax .get_figure (root = True ),'canvas' ,None )
122+ )
121123
122124def connect_event (self ,event ,callback ):
123125"""
@@ -1085,7 +1087,7 @@ def __init__(self, ax, labels, actives=None, *, useblit=True,
10851087
10861088def _clear (self ,event ):
10871089"""Internal event handler to clear the buttons."""
1088- if self .ignore (event )or self .canvas .is_saving ():
1090+ if self .ignore (event )or self .canvas is None or self . canvas .is_saving ():
10891091return
10901092self ._background = self .canvas .copy_from_bbox (self .ax .bbox )
10911093self .ax .draw_artist (self ._checks )
@@ -1663,7 +1665,7 @@ def __init__(self, ax, labels, active=0, activecolor=None, *,
16631665
16641666def _clear (self ,event ):
16651667"""Internal event handler to clear the buttons."""
1666- if self .ignore (event )or self .canvas .is_saving ():
1668+ if self .ignore (event )or self .canvas is None or self . canvas .is_saving ():
16671669return
16681670self ._background = self .canvas .copy_from_bbox (self .ax .bbox )
16691671self .ax .draw_artist (self ._buttons )
@@ -2181,6 +2183,8 @@ def connect_default_events(self):
21812183
21822184def ignore (self ,event ):
21832185# docstring inherited
2186+ if self .canvas is None :
2187+ return True
21842188if not self .active or not self .ax .get_visible ():
21852189return True
21862190# If canvas was locked