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

Skip to content

Commit b58d4a3

Browse files
Issue #19085: Fix running test_ttk_textonly on displayless host.
2 parents 20acaa7 + 2028e01 commit b58d4a3

2 files changed

Lines changed: 16 additions & 9 deletions

File tree

Lib/tkinter/test/test_tkinter/test_widgets.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
from test.support import requires
55

66
from tkinter.test.support import tcl_version, requires_tcl, widget_eq
7-
from tkinter.test.widget_tests import (add_standard_options, noconv,
7+
from tkinter.test.widget_tests import (
8+
add_standard_options, noconv, pixels_round,
89
AbstractWidgetTest, StandardOptionsTests, IntegerSizeTests, PixelSizeTests)
910

1011
requires('gui')
@@ -243,7 +244,7 @@ class MenubuttonTest(AbstractLabelTest, unittest.TestCase):
243244
'takefocus', 'text', 'textvariable',
244245
'underline', 'width', 'wraplength',
245246
)
246-
_conv_pixels = AbstractWidgetTest._conv_pixels
247+
_conv_pixels = staticmethod(pixels_round)
247248

248249
def _create(self, **kwargs):
249250
return tkinter.Menubutton(self.root, **kwargs)

Lib/tkinter/test/widget_tests.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,24 @@
1212
if tcl_version[:2] == (8, 5):
1313
# Issue #19085: Workaround a bug in Tk
1414
# http://core.tcl.tk/tk/info/3497848
15-
root = setup_master()
16-
patchlevel = root.call('info', 'patchlevel')
17-
patchlevel = tuple(map(int, patchlevel.split('.')))
18-
if patchlevel < (8, 5, 12):
19-
pixels_round = int
20-
del root
15+
_pixels_round = None
16+
def pixels_round(x):
17+
global _pixels_round
18+
if _pixels_round is None:
19+
root = setup_master()
20+
patchlevel = root.call('info', 'patchlevel')
21+
patchlevel = tuple(map(int, patchlevel.split('.')))
22+
if patchlevel < (8, 5, 12):
23+
_pixels_round = int
24+
else:
25+
_pixels_round = int_round
26+
return _pixels_round(x)
2127

2228

2329
_sentinel = object()
2430

2531
class AbstractWidgetTest:
26-
_conv_pixels = pixels_round
32+
_conv_pixels = staticmethod(pixels_round)
2733
_conv_pad_pixels = None
2834
wantobjects = True
2935

0 commit comments

Comments
 (0)