88from test .test_tkinter .support import setUpModule # noqa: F401
99from test .test_tkinter .support import (
1010 AbstractTkTest , requires_tk , tk_version , get_tk_patchlevel ,
11- simulate_mouse_click , AbstractDefaultRootTest )
11+ simulate_mouse_click , wait_until_mapped , AbstractDefaultRootTest )
1212from test .test_tkinter .widget_tests import (add_standard_options ,
1313 AbstractWidgetTest , StandardOptionsTests , IntegerSizeTests , PixelSizeTests )
1414
@@ -78,11 +78,13 @@ def setUp(self):
7878 self .widget .pack ()
7979
8080 def test_identify (self ):
81- self .widget .update ()
82- self .assertEqual (self .widget .identify (
83- int (self .widget .winfo_width () / 2 ),
84- int (self .widget .winfo_height () / 2 )
85- ), "label" )
81+ # Identifying the element under a point requires the widget to be
82+ # mapped with a real size; the rest of the checks do not.
83+ if wait_until_mapped (self .widget ):
84+ self .assertEqual (self .widget .identify (
85+ int (self .widget .winfo_width () / 2 ),
86+ int (self .widget .winfo_height () / 2 )
87+ ), "label" )
8688 self .assertEqual (self .widget .identify (- 1 , - 1 ), "" )
8789
8890 self .assertRaises (tkinter .TclError , self .widget .identify , None , 5 )
@@ -373,9 +375,11 @@ def test_bbox(self):
373375
374376 def test_identify (self ):
375377 self .entry .pack ()
376- self .entry .update ()
377378
378- self .assertIn (self .entry .identify (5 , 5 ), self .IDENTIFY_AS )
379+ # Identifying the element under a point requires the widget to be
380+ # mapped with a real size; the rest of the checks do not.
381+ if wait_until_mapped (self .entry ):
382+ self .assertIn (self .entry .identify (5 , 5 ), self .IDENTIFY_AS )
379383 self .assertEqual (self .entry .identify (- 1 , - 1 ), "" )
380384
381385 self .assertRaises (tkinter .TclError , self .entry .identify , None , 5 )
@@ -491,7 +495,7 @@ def test_virtual_event(self):
491495 self .combo .bind ('<<ComboboxSelected>>' ,
492496 lambda evt : success .append (True ))
493497 self .combo .pack ()
494- self .combo . update ( )
498+ self .require_mapped ( self . combo )
495499
496500 height = self .combo .winfo_height ()
497501 self ._show_drop_down_listbox ()
@@ -506,7 +510,7 @@ def test_configure_postcommand(self):
506510
507511 self .combo ['postcommand' ] = lambda : success .append (True )
508512 self .combo .pack ()
509- self .combo . update ( )
513+ self .require_mapped ( self . combo )
510514
511515 self ._show_drop_down_listbox ()
512516 self .assertTrue (success )
@@ -853,8 +857,10 @@ def test_get(self):
853857 else :
854858 conv = float
855859
856- scale_width = self .scale .winfo_width ()
857- self .assertEqual (self .scale .get (scale_width , 0 ), self .scale ['to' ])
860+ # Reading the value at the far edge needs the realized width.
861+ if wait_until_mapped (self .scale ):
862+ scale_width = self .scale .winfo_width ()
863+ self .assertEqual (self .scale .get (scale_width , 0 ), self .scale ['to' ])
858864
859865 self .assertEqual (conv (self .scale .get (0 , 0 )), conv (self .scale ['from' ]))
860866 self .assertEqual (self .scale .get (), self .scale ['value' ])
@@ -896,7 +902,10 @@ def test_set(self):
896902 # nevertheless, note that the max/min values we can get specifying
897903 # x, y coords are the ones according to the current range
898904 self .assertEqual (conv (self .scale .get (0 , 0 )), min )
899- self .assertEqual (conv (self .scale .get (self .scale .winfo_width (), 0 )), max )
905+ # Reading the value at the far edge needs the realized width.
906+ if wait_until_mapped (self .scale ):
907+ self .assertEqual (
908+ conv (self .scale .get (self .scale .winfo_width (), 0 )), max )
900909
901910 self .assertRaises (tkinter .TclError , self .scale .set , None )
902911
@@ -1238,6 +1247,7 @@ def create(self, **kwargs):
12381247 return ttk .Spinbox (self .root , ** kwargs )
12391248
12401249 def _click_increment_arrow (self ):
1250+ self .require_mapped (self .spin )
12411251 width = self .spin .winfo_width ()
12421252 height = self .spin .winfo_height ()
12431253 x = width - 5
@@ -1248,6 +1258,7 @@ def _click_increment_arrow(self):
12481258 self .spin .update_idletasks ()
12491259
12501260 def _click_decrement_arrow (self ):
1261+ self .require_mapped (self .spin )
12511262 width = self .spin .winfo_width ()
12521263 height = self .spin .winfo_height ()
12531264 x = width - 5
0 commit comments