@@ -117,7 +117,9 @@ def __init__(self, ax):
117
117
self .ax = ax
118
118
self ._cids = []
119
119
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
+ )
121
123
122
124
def connect_event (self , event , callback ):
123
125
"""
@@ -1085,7 +1087,7 @@ def __init__(self, ax, labels, actives=None, *, useblit=True,
1085
1087
1086
1088
def _clear (self , event ):
1087
1089
"""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 ():
1089
1091
return
1090
1092
self ._background = self .canvas .copy_from_bbox (self .ax .bbox )
1091
1093
self .ax .draw_artist (self ._checks )
@@ -1663,7 +1665,7 @@ def __init__(self, ax, labels, active=0, activecolor=None, *,
1663
1665
1664
1666
def _clear (self , event ):
1665
1667
"""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 ():
1667
1669
return
1668
1670
self ._background = self .canvas .copy_from_bbox (self .ax .bbox )
1669
1671
self .ax .draw_artist (self ._buttons )
@@ -2181,6 +2183,8 @@ def connect_default_events(self):
2181
2183
2182
2184
def ignore (self , event ):
2183
2185
# docstring inherited
2186
+ if self .canvas is None :
2187
+ return True
2184
2188
if not self .active or not self .ax .get_visible ():
2185
2189
return True
2186
2190
# If canvas was locked
0 commit comments