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

Skip to content

Commit 98b1a76

Browse files
committed
FIX: add guardrails for too big tk figures on linux
Depending on the version of xserver creating a too big tk window either corrupts xorg (!) or causes the process to exit. This adds a guard rail that will convert this into a python exception instead. closes #17460
1 parent 3964e71 commit 98b1a76

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

lib/matplotlib/backends/_backend_tk.py

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

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

436446
def show(self):

0 commit comments

Comments
 (0)