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

Skip to content

Commit 89fa0e4

Browse files
authored
Merge pull request #17470 from tacaswell/fix_too-big-tk
FIX: add guardrails for too big tk figures
2 parents e7d498c + 32b914f commit 89fa0e4

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

lib/matplotlib/backends/_backend_tk.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,17 @@ def _get_toolbar(self):
431431
return toolbar
432432

433433
def resize(self, width, height):
434+
max_size = 1_400_000 # the measured max on xorg 1.20.8 was 1_409_023
435+
436+
if (width > max_size or height > max_size) and sys.platform == 'linux':
437+
raise ValueError(
438+
'You have requested to resize the '
439+
f'Tk window to ({width}, {height}), one of which '
440+
f'is bigger than {max_size}. At larger sizes xorg will '
441+
'either exit with an error on newer versions (~1.20) or '
442+
'cause corruption on older version (~1.19). We '
443+
'do not expect a window over a million pixel wide or tall '
444+
'to be intended behavior.')
434445
self.canvas._tkcanvas.configure(width=width, height=height)
435446

436447
def show(self):

0 commit comments

Comments
 (0)