Debian Codegraph @

cpython27/Lib/lib-tk/test/test_tkinter/test_widgets.py

raw symbols SCIP
1 import unittest
2 import Tkinter as tkinter
3 from Tkinter import TclError
4 import os
5 import sys
6 from test.test_support import requires, run_unittest
7
8 from test_ttk.support import (tcl_version, requires_tcl, get_tk_patchlevel,
9 widget_eq)
10 from widget_tests import (
11 add_standard_options, noconv, noconv_meth, int_round, pixels_round,
12 AbstractWidgetTest, StandardOptionsTests,
13 IntegerSizeTests, PixelSizeTests,
14 setUpModule)
15
16 requires('gui')
17
18
19 class AbstractToplevelTest(AbstractWidgetTest, PixelSizeTests):
20 _conv_pad_pixels = noconv_meth
21
22 def test_class(self):
23 widget = self.create()
24 self.assertEqual(widget['class'],
25 widget.__class__.__name__.title())
26 self.checkInvalidParam(widget, 'class', 'Foo',
27 errmsg="can't modify -class option after widget is created")
28 widget2 = self.create(class_='Foo')
29 self.assertEqual(widget2['class'], 'Foo')
30
31 def test_colormap(self):
32 widget = self.create()
33 self.assertEqual(widget['colormap'], '')
34 self.checkInvalidParam(widget, 'colormap', 'new',
35 errmsg="can't modify -colormap option after widget is created")
36 widget2 = self.create(colormap='new')
37 self.assertEqual(widget2['colormap'], 'new')
38
39 def test_container(self):
40 widget = self.create()
41 self.assertEqual(widget['container'], 0 if self.wantobjects else '0')
42 self.checkInvalidParam(widget, 'container', 1,
43 errmsg="can't modify -container option after widget is created")
44 widget2 = self.create(container=True)
45 self.assertEqual(widget2['container'], 1 if self.wantobjects else '1')
46
47 def test_visual(self):
48 widget = self.create()
49 self.assertEqual(widget['visual'], '')
50 self.checkInvalidParam(widget, 'visual', 'default',
51 errmsg="can't modify -visual option after widget is created")
52 widget2 = self.create(visual='default')
53 self.assertEqual(widget2['visual'], 'default')
54
55
56 @add_standard_options(StandardOptionsTests)
57 class ToplevelTest(AbstractToplevelTest, unittest.TestCase):
58 OPTIONS = (
59 'background', 'borderwidth',
60 'class', 'colormap', 'container', 'cursor', 'height',
61 'highlightbackground', 'highlightcolor', 'highlightthickness',
62 'menu', 'padx', 'pady', 'relief', 'screen',
63 'takefocus', 'use', 'visual', 'width',
64 )
65
66 def create(self, **kwargs):
67 return tkinter.Toplevel(self.root, **kwargs)
68
69 def test_menu(self):
70 widget = self.create()
71 menu = tkinter.Menu(self.root)
72 self.checkParam(widget, 'menu', menu, eq=widget_eq)
73 self.checkParam(widget, 'menu', '')
74
75 def test_screen(self):
76 widget = self.create()
77 self.assertEqual(widget['screen'], '')
78 try:
79 display = os.environ['DISPLAY']
80 except KeyError:
81 self.skipTest('No $DISPLAY set.')
82 self.checkInvalidParam(widget, 'screen', display,
83 errmsg="can't modify -screen option after widget is created")
84 widget2 = self.create(screen=display)
85 self.assertEqual(widget2['screen'], display)
86
87 def test_use(self):
88 widget = self.create()
89 self.assertEqual(widget['use'], '')
90 parent = self.create(container=True)
91 # hex() adds the 'L' suffix for longs
92 wid = '%#x' % parent.winfo_id()
93 widget2 = self.create(use=wid)
94 self.assertEqual(widget2['use'], wid)
95
96
97 @add_standard_options(StandardOptionsTests)
98 class FrameTest(AbstractToplevelTest, unittest.TestCase):
99 OPTIONS = (
100 'background', 'borderwidth',
101 'class', 'colormap', 'container', 'cursor', 'height',
102 'highlightbackground', 'highlightcolor', 'highlightthickness',
103 'padx', 'pady', 'relief', 'takefocus', 'visual', 'width',
104 )
105
106 def create(self, **kwargs):
107 return tkinter.Frame(self.root, **kwargs)
108
109
110 @add_standard_options(StandardOptionsTests)
111 class LabelFrameTest(AbstractToplevelTest, unittest.TestCase):
112 OPTIONS = (
113 'background', 'borderwidth',
114 'class', 'colormap', 'container', 'cursor',
115 'font', 'foreground', 'height',
116 'highlightbackground', 'highlightcolor', 'highlightthickness',
117 'labelanchor', 'labelwidget', 'padx', 'pady', 'relief',
118 'takefocus', 'text', 'visual', 'width',
119 )
120
121 def create(self, **kwargs):
122 return tkinter.LabelFrame(self.root, **kwargs)
123
124 def test_labelanchor(self):
125 widget = self.create()
126 self.checkEnumParam(widget, 'labelanchor',
127 'e', 'en', 'es', 'n', 'ne', 'nw',
128 's', 'se', 'sw', 'w', 'wn', 'ws')
129 self.checkInvalidParam(widget, 'labelanchor', 'center')
130
131 def test_labelwidget(self):
132 widget = self.create()
133 label = tkinter.Label(self.root, text='Mupp', name='foo')
134 self.checkParam(widget, 'labelwidget', label, expected='.foo')
135 label.destroy()
136
137
138 class AbstractLabelTest(AbstractWidgetTest, IntegerSizeTests):
139 _conv_pixels = noconv_meth
140
141 def test_highlightthickness(self):
142 widget = self.create()
143 self.checkPixelsParam(widget, 'highlightthickness',
144 0, 1.3, 2.6, 6, -2, '10p')
145
146
147 @add_standard_options(StandardOptionsTests)
148 class LabelTest(AbstractLabelTest, unittest.TestCase):
149 OPTIONS = (
150 'activebackground', 'activeforeground', 'anchor',
151 'background', 'bitmap', 'borderwidth', 'compound', 'cursor',
152 'disabledforeground', 'font', 'foreground', 'height',
153 'highlightbackground', 'highlightcolor', 'highlightthickness',
154 'image', 'justify', 'padx', 'pady', 'relief', 'state',
155 'takefocus', 'text', 'textvariable',
156 'underline', 'width', 'wraplength',
157 )
158
159 def create(self, **kwargs):
160 return tkinter.Label(self.root, **kwargs)
161
162
163 @add_standard_options(StandardOptionsTests)
164 class ButtonTest(AbstractLabelTest, unittest.TestCase):
165 OPTIONS = (
166 'activebackground', 'activeforeground', 'anchor',
167 'background', 'bitmap', 'borderwidth',
168 'command', 'compound', 'cursor', 'default',
169 'disabledforeground', 'font', 'foreground', 'height',
170 'highlightbackground', 'highlightcolor', 'highlightthickness',
171 'image', 'justify', 'overrelief', 'padx', 'pady', 'relief',
172 'repeatdelay', 'repeatinterval',
173 'state', 'takefocus', 'text', 'textvariable',
174 'underline', 'width', 'wraplength')
175
176 def create(self, **kwargs):
177 return tkinter.Button(self.root, **kwargs)
178
179 def test_default(self):
180 widget = self.create()
181 self.checkEnumParam(widget, 'default', 'active', 'disabled', 'normal')
182
183
184 @add_standard_options(StandardOptionsTests)
185 class CheckbuttonTest(AbstractLabelTest, unittest.TestCase):
186 OPTIONS = (
187 'activebackground', 'activeforeground', 'anchor',
188 'background', 'bitmap', 'borderwidth',
189 'command', 'compound', 'cursor',
190 'disabledforeground', 'font', 'foreground', 'height',
191 'highlightbackground', 'highlightcolor', 'highlightthickness',
192 'image', 'indicatoron', 'justify',
193 'offrelief', 'offvalue', 'onvalue', 'overrelief',
194 'padx', 'pady', 'relief', 'selectcolor', 'selectimage', 'state',
195 'takefocus', 'text', 'textvariable',
196 'tristateimage', 'tristatevalue',
197 'underline', 'variable', 'width', 'wraplength',
198 )
199
200 def create(self, **kwargs):
201 return tkinter.Checkbutton(self.root, **kwargs)
202
203
204 def test_offvalue(self):
205 widget = self.create()
206 self.checkParams(widget, 'offvalue', 1, 2.3, '', 'any string')
207
208 def test_onvalue(self):
209 widget = self.create()
210 self.checkParams(widget, 'onvalue', 1, 2.3, '', 'any string')
211
212
213 @add_standard_options(StandardOptionsTests)
214 class RadiobuttonTest(AbstractLabelTest, unittest.TestCase):
215 OPTIONS = (
216 'activebackground', 'activeforeground', 'anchor',
217 'background', 'bitmap', 'borderwidth',
218 'command', 'compound', 'cursor',
219 'disabledforeground', 'font', 'foreground', 'height',
220 'highlightbackground', 'highlightcolor', 'highlightthickness',
221 'image', 'indicatoron', 'justify', 'offrelief', 'overrelief',
222 'padx', 'pady', 'relief', 'selectcolor', 'selectimage', 'state',
223 'takefocus', 'text', 'textvariable',
224 'tristateimage', 'tristatevalue',
225 'underline', 'value', 'variable', 'width', 'wraplength',
226 )
227
228 def create(self, **kwargs):
229 return tkinter.Radiobutton(self.root, **kwargs)
230
231 def test_value(self):
232 widget = self.create()
233 self.checkParams(widget, 'value', 1, 2.3, '', 'any string')
234
235
236 @add_standard_options(StandardOptionsTests)
237 class MenubuttonTest(AbstractLabelTest, unittest.TestCase):
238 OPTIONS = (
239 'activebackground', 'activeforeground', 'anchor',
240 'background', 'bitmap', 'borderwidth',
241 'compound', 'cursor', 'direction',
242 'disabledforeground', 'font', 'foreground', 'height',
243 'highlightbackground', 'highlightcolor', 'highlightthickness',
244 'image', 'indicatoron', 'justify', 'menu',
245 'padx', 'pady', 'relief', 'state',
246 'takefocus', 'text', 'textvariable',
247 'underline', 'width', 'wraplength',
248 )
249 _conv_pixels = staticmethod(pixels_round)
250
251 def create(self, **kwargs):
252 return tkinter.Menubutton(self.root, **kwargs)
253
254 def test_direction(self):
255 widget = self.create()
256 self.checkEnumParam(widget, 'direction',
257 'above', 'below', 'flush', 'left', 'right')
258
259 def test_height(self):
260 widget = self.create()
261 self.checkIntegerParam(widget, 'height', 100, -100, 0, conv=str)
262
263 test_highlightthickness = StandardOptionsTests.test_highlightthickness.im_func
264
265 @unittest.skipIf(sys.platform == 'darwin',
266 'crashes with Cocoa Tk (issue19733)')
267 def test_image(self):
268 widget = self.create()
269 image = tkinter.PhotoImage(master=self.root, name='image1')
270 self.checkParam(widget, 'image', image, conv=str)
271 errmsg = 'image "spam" doesn\'t exist'
272 with self.assertRaises(tkinter.TclError) as cm:
273 widget['image'] = 'spam'
274 if errmsg is not None:
275 self.assertEqual(str(cm.exception), errmsg)
276 with self.assertRaises(tkinter.TclError) as cm:
277 widget.configure({'image': 'spam'})
278 if errmsg is not None:
279 self.assertEqual(str(cm.exception), errmsg)
280
281 def test_menu(self):
282 widget = self.create()
283 menu = tkinter.Menu(widget, name='menu')
284 self.checkParam(widget, 'menu', menu, eq=widget_eq)
285 menu.destroy()
286
287 def test_padx(self):
288 widget = self.create()
289 self.checkPixelsParam(widget, 'padx', 3, 4.4, 5.6, '12m')
290 self.checkParam(widget, 'padx', -2, expected=0)
291
292 def test_pady(self):
293 widget = self.create()
294 self.checkPixelsParam(widget, 'pady', 3, 4.4, 5.6, '12m')
295 self.checkParam(widget, 'pady', -2, expected=0)
296
297 def test_width(self):
298 widget = self.create()
299 self.checkIntegerParam(widget, 'width', 402, -402, 0, conv=str)
300
301
302 class OptionMenuTest(MenubuttonTest, unittest.TestCase):
303
304 def create(self, default='b', values=('a', 'b', 'c'), **kwargs):
305 return tkinter.OptionMenu(self.root, None, default, *values, **kwargs)
306
307
308 @add_standard_options(IntegerSizeTests, StandardOptionsTests)
309 class EntryTest(AbstractWidgetTest, unittest.TestCase):
310 OPTIONS = (
311 'background', 'borderwidth', 'cursor',
312 'disabledbackground', 'disabledforeground',
313 'exportselection', 'font', 'foreground',
314 'highlightbackground', 'highlightcolor', 'highlightthickness',
315 'insertbackground', 'insertborderwidth',
316 'insertofftime', 'insertontime', 'insertwidth',
317 'invalidcommand', 'justify', 'readonlybackground', 'relief',
318 'selectbackground', 'selectborderwidth', 'selectforeground',
319 'show', 'state', 'takefocus', 'textvariable',
320 'validate', 'validatecommand', 'width', 'xscrollcommand',
321 )
322
323 def create(self, **kwargs):
324 return tkinter.Entry(self.root, **kwargs)
325
326 def test_disabledbackground(self):
327 widget = self.create()
328 self.checkColorParam(widget, 'disabledbackground')
329
330 def test_insertborderwidth(self):
331 widget = self.create(insertwidth=100)
332 self.checkPixelsParam(widget, 'insertborderwidth',
333 0, 1.3, 2.6, 6, -2, '10p')
334 # insertborderwidth is bounded above by a half of insertwidth.
335 self.checkParam(widget, 'insertborderwidth', 60, expected=100//2)
336
337 def test_insertwidth(self):
338 widget = self.create()
339 self.checkPixelsParam(widget, 'insertwidth', 1.3, 3.6, '10p')
340 self.checkParam(widget, 'insertwidth', 0.1, expected=2)
341 self.checkParam(widget, 'insertwidth', -2, expected=2)
342 if pixels_round(0.9) <= 0:
343 self.checkParam(widget, 'insertwidth', 0.9, expected=2)
344 else:
345 self.checkParam(widget, 'insertwidth', 0.9, expected=1)
346
347 def test_invalidcommand(self):
348 widget = self.create()
349 self.checkCommandParam(widget, 'invalidcommand')
350 self.checkCommandParam(widget, 'invcmd')
351
352 def test_readonlybackground(self):
353 widget = self.create()
354 self.checkColorParam(widget, 'readonlybackground')
355
356 def test_show(self):
357 widget = self.create()
358 self.checkParam(widget, 'show', '*')
359 self.checkParam(widget, 'show', '')
360 self.checkParam(widget, 'show', ' ')
361
362 def test_state(self):
363 widget = self.create()
364 self.checkEnumParam(widget, 'state',
365 'disabled', 'normal', 'readonly')
366
367 def test_validate(self):
368 widget = self.create()
369 self.checkEnumParam(widget, 'validate',
370 'all', 'key', 'focus', 'focusin', 'focusout', 'none')
371
372 def test_validatecommand(self):
373 widget = self.create()
374 self.checkCommandParam(widget, 'validatecommand')
375 self.checkCommandParam(widget, 'vcmd')
376
377
378 @add_standard_options(StandardOptionsTests)
379 class SpinboxTest(EntryTest, unittest.TestCase):
380 OPTIONS = (
381 'activebackground', 'background', 'borderwidth',
382 'buttonbackground', 'buttoncursor', 'buttondownrelief', 'buttonuprelief',
383 'command', 'cursor', 'disabledbackground', 'disabledforeground',
384 'exportselection', 'font', 'foreground', 'format', 'from',
385 'highlightbackground', 'highlightcolor', 'highlightthickness',
386 'increment',
387 'insertbackground', 'insertborderwidth',
388 'insertofftime', 'insertontime', 'insertwidth',
389 'invalidcommand', 'justify', 'relief', 'readonlybackground',
390 'repeatdelay', 'repeatinterval',
391 'selectbackground', 'selectborderwidth', 'selectforeground',
392 'state', 'takefocus', 'textvariable', 'to',
393 'validate', 'validatecommand', 'values',
394 'width', 'wrap', 'xscrollcommand',
395 )
396
397 def create(self, **kwargs):
398 return tkinter.Spinbox(self.root, **kwargs)
399
400 test_show = None
401
402 def test_buttonbackground(self):
403 widget = self.create()
404 self.checkColorParam(widget, 'buttonbackground')
405
406 def test_buttoncursor(self):
407 widget = self.create()
408 self.checkCursorParam(widget, 'buttoncursor')
409
410 def test_buttondownrelief(self):
411 widget = self.create()
412 self.checkReliefParam(widget, 'buttondownrelief')
413
414 def test_buttonuprelief(self):
415 widget = self.create()
416 self.checkReliefParam(widget, 'buttonuprelief')
417
418 def test_format(self):
419 widget = self.create()
420 self.checkParam(widget, 'format', '%2f')
421 self.checkParam(widget, 'format', '%2.2f')
422 self.checkParam(widget, 'format', '%.2f')
423 self.checkParam(widget, 'format', '%2.f')
424 self.checkInvalidParam(widget, 'format', '%2e-1f')
425 self.checkInvalidParam(widget, 'format', '2.2')
426 self.checkInvalidParam(widget, 'format', '%2.-2f')
427 self.checkParam(widget, 'format', '%-2.02f')
428 self.checkParam(widget, 'format', '% 2.02f')
429 self.checkParam(widget, 'format', '% -2.200f')
430 self.checkParam(widget, 'format', '%09.200f')
431 self.checkInvalidParam(widget, 'format', '%d')
432
433 def test_from(self):
434 widget = self.create()
435 self.checkParam(widget, 'to', 100.0)
436 self.checkFloatParam(widget, 'from', -10, 10.2, 11.7)
437 self.checkInvalidParam(widget, 'from', 200,
438 errmsg='-to value must be greater than -from value')
439
440 def test_increment(self):
441 widget = self.create()
442 self.checkFloatParam(widget, 'increment', -1, 1, 10.2, 12.8, 0)
443
444 def test_to(self):
445 widget = self.create()
446 self.checkParam(widget, 'from', -100.0)
447 self.checkFloatParam(widget, 'to', -10, 10.2, 11.7)
448 self.checkInvalidParam(widget, 'to', -200,
449 errmsg='-to value must be greater than -from value')
450
451 def test_values(self):
452 # XXX
453 widget = self.create()
454 self.assertEqual(widget['values'], '')
455 self.checkParam(widget, 'values', 'mon tue wed thur')
456 self.checkParam(widget, 'values', ('mon', 'tue', 'wed', 'thur'),
457 expected='mon tue wed thur')
458 self.checkParam(widget, 'values', (42, 3.14, '', 'any string'),
459 expected='42 3.14 {} {any string}')
460 self.checkParam(widget, 'values', '')
461
462 def test_wrap(self):
463 widget = self.create()
464 self.checkBooleanParam(widget, 'wrap')
465
466 def test_bbox(self):
467 widget = self.create()
468 self.assertIsBoundingBox(widget.bbox(0))
469 self.assertRaises(tkinter.TclError, widget.bbox, 'noindex')
470 self.assertRaises(tkinter.TclError, widget.bbox, None)
471 self.assertRaises(TypeError, widget.bbox)
472 self.assertRaises(TypeError, widget.bbox, 0, 1)
473
474 def test_selection_element(self):
475 widget = self.create()
476 self.assertEqual(widget.selection_element(), "none")
477 widget.selection_element("buttonup")
478 self.assertEqual(widget.selection_element(), "buttonup")
479 widget.selection_element("buttondown")
480 self.assertEqual(widget.selection_element(), "buttondown")
481
482
483 @add_standard_options(StandardOptionsTests)
484 class TextTest(AbstractWidgetTest, unittest.TestCase):
485 OPTIONS = (
486 'autoseparators', 'background', 'blockcursor', 'borderwidth',
487 'cursor', 'endline', 'exportselection',
488 'font', 'foreground', 'height',
489 'highlightbackground', 'highlightcolor', 'highlightthickness',
490 'inactiveselectbackground', 'insertbackground', 'insertborderwidth',
491 'insertofftime', 'insertontime', 'insertunfocussed', 'insertwidth',
492 'maxundo', 'padx', 'pady', 'relief',
493 'selectbackground', 'selectborderwidth', 'selectforeground',
494 'setgrid', 'spacing1', 'spacing2', 'spacing3', 'startline', 'state',
495 'tabs', 'tabstyle', 'takefocus', 'undo', 'width', 'wrap',
496 'xscrollcommand', 'yscrollcommand',
497 )
498 if tcl_version < (8, 5):
499 _stringify = True
500
501 def create(self, **kwargs):
502 return tkinter.Text(self.root, **kwargs)
503
504 def test_autoseparators(self):
505 widget = self.create()
506 self.checkBooleanParam(widget, 'autoseparators')
507
508 @requires_tcl(8, 5)
509 def test_blockcursor(self):
510 widget = self.create()
511 self.checkBooleanParam(widget, 'blockcursor')
512
513 @requires_tcl(8, 5)
514 def test_endline(self):
515 widget = self.create()
516 text = '\n'.join('Line %d' for i in range(100))
517 widget.insert('end', text)
518 self.checkParam(widget, 'endline', 200, expected='')
519 self.checkParam(widget, 'endline', -10, expected='')
520 self.checkInvalidParam(widget, 'endline', 'spam',
521 errmsg='expected integer but got "spam"')
522 self.checkParam(widget, 'endline', 50)
523 self.checkParam(widget, 'startline', 15)
524 self.checkInvalidParam(widget, 'endline', 10,
525 errmsg='-startline must be less than or equal to -endline')
526
527 def test_height(self):
528 widget = self.create()
529 self.checkPixelsParam(widget, 'height', 100, 101.2, 102.6, '3c')
530 self.checkParam(widget, 'height', -100, expected=1)
531 self.checkParam(widget, 'height', 0, expected=1)
532
533 def test_maxundo(self):
534 widget = self.create()
535 self.checkIntegerParam(widget, 'maxundo', 0, 5, -1)
536
537 @requires_tcl(8, 5)
538 def test_inactiveselectbackground(self):
539 widget = self.create()
540 self.checkColorParam(widget, 'inactiveselectbackground')
541
542 @requires_tcl(8, 6)
543 def test_insertunfocussed(self):
544 widget = self.create()
545 self.checkEnumParam(widget, 'insertunfocussed',
546 'hollow', 'none', 'solid')
547
548 def test_selectborderwidth(self):
549 widget = self.create()
550 self.checkPixelsParam(widget, 'selectborderwidth',
551 1.3, 2.6, -2, '10p', conv=noconv,
552 keep_orig=tcl_version >= (8, 5))
553
554 def test_spacing1(self):
555 widget = self.create()
556 self.checkPixelsParam(widget, 'spacing1', 20, 21.4, 22.6, '0.5c')
557 self.checkParam(widget, 'spacing1', -5, expected=0)
558
559 def test_spacing2(self):
560 widget = self.create()
561 self.checkPixelsParam(widget, 'spacing2', 5, 6.4, 7.6, '0.1c')
562 self.checkParam(widget, 'spacing2', -1, expected=0)
563
564 def test_spacing3(self):
565 widget = self.create()
566 self.checkPixelsParam(widget, 'spacing3', 20, 21.4, 22.6, '0.5c')
567 self.checkParam(widget, 'spacing3', -10, expected=0)
568
569 @requires_tcl(8, 5)
570 def test_startline(self):
571 widget = self.create()
572 text = '\n'.join('Line %d' for i in range(100))
573 widget.insert('end', text)
574 self.checkParam(widget, 'startline', 200, expected='')
575 self.checkParam(widget, 'startline', -10, expected='')
576 self.checkInvalidParam(widget, 'startline', 'spam',
577 errmsg='expected integer but got "spam"')
578 self.checkParam(widget, 'startline', 10)
579 self.checkParam(widget, 'endline', 50)
580 self.checkInvalidParam(widget, 'startline', 70,
581 errmsg='-startline must be less than or equal to -endline')
582
583 def test_state(self):
584 widget = self.create()
585 if tcl_version < (8, 5):
586 self.checkParams(widget, 'state', 'disabled', 'normal')
587 else:
588 self.checkEnumParam(widget, 'state', 'disabled', 'normal')
589
590 def test_tabs(self):
591 widget = self.create()
592 if get_tk_patchlevel() < (8, 5, 11):
593 self.checkParam(widget, 'tabs', (10.2, 20.7, '1i', '2i'),
594 expected=('10.2', '20.7', '1i', '2i'))
595 else:
596 self.checkParam(widget, 'tabs', (10.2, 20.7, '1i', '2i'))
597 self.checkParam(widget, 'tabs', '10.2 20.7 1i 2i',
598 expected=('10.2', '20.7', '1i', '2i'))
599 self.checkParam(widget, 'tabs', '2c left 4c 6c center',
600 expected=('2c', 'left', '4c', '6c', 'center'))
601 self.checkInvalidParam(widget, 'tabs', 'spam',
602 errmsg='bad screen distance "spam"',
603 keep_orig=tcl_version >= (8, 5))
604
605 @requires_tcl(8, 5)
606 def test_tabstyle(self):
607 widget = self.create()
608 self.checkEnumParam(widget, 'tabstyle', 'tabular', 'wordprocessor')
609
610 def test_undo(self):
611 widget = self.create()
612 self.checkBooleanParam(widget, 'undo')
613
614 def test_width(self):
615 widget = self.create()
616 self.checkIntegerParam(widget, 'width', 402)
617 self.checkParam(widget, 'width', -402, expected=1)
618 self.checkParam(widget, 'width', 0, expected=1)
619
620 def test_wrap(self):
621 widget = self.create()
622 if tcl_version < (8, 5):
623 self.checkParams(widget, 'wrap', 'char', 'none', 'word')
624 else:
625 self.checkEnumParam(widget, 'wrap', 'char', 'none', 'word')
626
627 def test_bbox(self):
628 widget = self.create()
629 self.assertIsBoundingBox(widget.bbox('1.1'))
630 self.assertIsNone(widget.bbox('end'))
631 self.assertRaises(tkinter.TclError, widget.bbox, 'noindex')
632 self.assertRaises(tkinter.TclError, widget.bbox, None)
633 self.assertRaises(tkinter.TclError, widget.bbox)
634 self.assertRaises(tkinter.TclError, widget.bbox, '1.1', 'end')
635
636
637 @add_standard_options(PixelSizeTests, StandardOptionsTests)
638 class CanvasTest(AbstractWidgetTest, unittest.TestCase):
639 OPTIONS = (
640 'background', 'borderwidth',
641 'closeenough', 'confine', 'cursor', 'height',
642 'highlightbackground', 'highlightcolor', 'highlightthickness',
643 'insertbackground', 'insertborderwidth',
644 'insertofftime', 'insertontime', 'insertwidth',
645 'offset', 'relief', 'scrollregion',
646 'selectbackground', 'selectborderwidth', 'selectforeground',
647 'state', 'takefocus',
648 'xscrollcommand', 'xscrollincrement',
649 'yscrollcommand', 'yscrollincrement', 'width',
650 )
651
652 _conv_pixels = staticmethod(int_round)
653 _stringify = True
654
655 def create(self, **kwargs):
656 return tkinter.Canvas(self.root, **kwargs)
657
658 def test_closeenough(self):
659 widget = self.create()
660 self.checkFloatParam(widget, 'closeenough', 24, 2.4, 3.6, -3,
661 conv=float)
662
663 def test_confine(self):
664 widget = self.create()
665 self.checkBooleanParam(widget, 'confine')
666
667 def test_offset(self):
668 widget = self.create()
669 self.assertEqual(widget['offset'], '0,0')
670 self.checkParams(widget, 'offset',
671 'n', 'ne', 'e', 'se', 's', 'sw', 'w', 'nw', 'center')
672 self.checkParam(widget, 'offset', '10,20')
673 self.checkParam(widget, 'offset', '#5,6')
674 self.checkInvalidParam(widget, 'offset', 'spam')
675
676 def test_scrollregion(self):
677 widget = self.create()
678 self.checkParam(widget, 'scrollregion', '0 0 200 150')
679 self.checkParam(widget, 'scrollregion', (0, 0, 200, 150),
680 expected='0 0 200 150')
681 self.checkParam(widget, 'scrollregion', '')
682 self.checkInvalidParam(widget, 'scrollregion', 'spam',
683 errmsg='bad scrollRegion "spam"')
684 self.checkInvalidParam(widget, 'scrollregion', (0, 0, 200, 'spam'))
685 self.checkInvalidParam(widget, 'scrollregion', (0, 0, 200))
686 self.checkInvalidParam(widget, 'scrollregion', (0, 0, 200, 150, 0))
687
688 def test_state(self):
689 widget = self.create()
690 self.checkEnumParam(widget, 'state', 'disabled', 'normal',
691 errmsg='bad state value "{}": must be normal or disabled')
692
693 def test_xscrollincrement(self):
694 widget = self.create()
695 self.checkPixelsParam(widget, 'xscrollincrement',
696 40, 0, 41.2, 43.6, -40, '0.5i')
697
698 def test_yscrollincrement(self):
699 widget = self.create()
700 self.checkPixelsParam(widget, 'yscrollincrement',
701 10, 0, 11.2, 13.6, -10, '0.1i')
702
703
704 @add_standard_options(IntegerSizeTests, StandardOptionsTests)
705 class ListboxTest(AbstractWidgetTest, unittest.TestCase):
706 OPTIONS = (
707 'activestyle', 'background', 'borderwidth', 'cursor',
708 'disabledforeground', 'exportselection',
709 'font', 'foreground', 'height',
710 'highlightbackground', 'highlightcolor', 'highlightthickness',
711 'justify', 'listvariable', 'relief',
712 'selectbackground', 'selectborderwidth', 'selectforeground',
713 'selectmode', 'setgrid', 'state',
714 'takefocus', 'width', 'xscrollcommand', 'yscrollcommand',
715 )
716
717 def create(self, **kwargs):
718 return tkinter.Listbox(self.root, **kwargs)
719
720 def test_activestyle(self):
721 widget = self.create()
722 self.checkEnumParam(widget, 'activestyle',
723 'dotbox', 'none', 'underline')
724
725 test_justify = requires_tcl(8, 6, 5)(StandardOptionsTests.test_justify.im_func)
726
727 def test_listvariable(self):
728 widget = self.create()
729 var = tkinter.DoubleVar(self.root)
730 self.checkVariableParam(widget, 'listvariable', var)
731
732 def test_selectmode(self):
733 widget = self.create()
734 self.checkParam(widget, 'selectmode', 'single')
735 self.checkParam(widget, 'selectmode', 'browse')
736 self.checkParam(widget, 'selectmode', 'multiple')
737 self.checkParam(widget, 'selectmode', 'extended')
738
739 def test_state(self):
740 widget = self.create()
741 self.checkEnumParam(widget, 'state', 'disabled', 'normal')
742
743 def test_itemconfigure(self):
744 widget = self.create()
745 with self.assertRaisesRegexp(TclError, 'item number "0" out of range'):
746 widget.itemconfigure(0)
747 colors = 'red orange yellow green blue white violet'.split()
748 widget.insert('end', *colors)
749 for i, color in enumerate(colors):
750 widget.itemconfigure(i, background=color)
751 with self.assertRaises(TypeError):
752 widget.itemconfigure()
753 with self.assertRaisesRegexp(TclError, 'bad listbox index "red"'):
754 widget.itemconfigure('red')
755 self.assertEqual(widget.itemconfigure(0, 'background'),
756 ('background', 'background', 'Background', '', 'red'))
757 self.assertEqual(widget.itemconfigure('end', 'background'),
758 ('background', 'background', 'Background', '', 'violet'))
759 self.assertEqual(widget.itemconfigure('@0,0', 'background'),
760 ('background', 'background', 'Background', '', 'red'))
761
762 d = widget.itemconfigure(0)
763 self.assertIsInstance(d, dict)
764 for k, v in d.items():
765 self.assertIn(len(v), (2, 5))
766 if len(v) == 5:
767 self.assertEqual(v, widget.itemconfigure(0, k))
768 self.assertEqual(v[4], widget.itemcget(0, k))
769
770 def check_itemconfigure(self, name, value):
771 widget = self.create()
772 widget.insert('end', 'a', 'b', 'c', 'd')
773 widget.itemconfigure(0, **{name: value})
774 self.assertEqual(widget.itemconfigure(0, name)[4], value)
775 self.assertEqual(widget.itemcget(0, name), value)
776 with self.assertRaisesRegexp(TclError, 'unknown color name "spam"'):
777 widget.itemconfigure(0, **{name: 'spam'})
778
779 def test_itemconfigure_background(self):
780 self.check_itemconfigure('background', '#ff0000')
781
782 def test_itemconfigure_bg(self):
783 self.check_itemconfigure('bg', '#ff0000')
784
785 def test_itemconfigure_fg(self):
786 self.check_itemconfigure('fg', '#110022')
787
788 def test_itemconfigure_foreground(self):
789 self.check_itemconfigure('foreground', '#110022')
790
791 def test_itemconfigure_selectbackground(self):
792 self.check_itemconfigure('selectbackground', '#110022')
793
794 def test_itemconfigure_selectforeground(self):
795 self.check_itemconfigure('selectforeground', '#654321')
796
797 def test_box(self):
798 lb = self.create()
799 lb.insert(0, *('el%d' % i for i in range(8)))
800 lb.pack()
801 self.assertIsBoundingBox(lb.bbox(0))
802 self.assertIsNone(lb.bbox(-1))
803 self.assertIsNone(lb.bbox(10))
804 self.assertRaises(TclError, lb.bbox, 'noindex')
805 self.assertRaises(TclError, lb.bbox, None)
806 self.assertRaises(TypeError, lb.bbox)
807 self.assertRaises(TypeError, lb.bbox, 0, 1)
808
809 def test_curselection(self):
810 lb = self.create()
811 lb.insert(0, *('el%d' % i for i in range(8)))
812 lb.selection_clear(0, tkinter.END)
813 lb.selection_set(2, 4)
814 lb.selection_set(6)
815 self.assertEqual(lb.curselection(), (2, 3, 4, 6))
816 self.assertRaises(TypeError, lb.curselection, 0)
817
818 def test_get(self):
819 lb = self.create()
820 lb.insert(0, *('el%d' % i for i in range(8)))
821 self.assertEqual(lb.get(0), 'el0')
822 self.assertEqual(lb.get(3), 'el3')
823 self.assertEqual(lb.get('end'), 'el7')
824 self.assertEqual(lb.get(8), '')
825 self.assertEqual(lb.get(-1), '')
826 self.assertEqual(lb.get(3, 5), ('el3', 'el4', 'el5'))
827 self.assertEqual(lb.get(5, 'end'), ('el5', 'el6', 'el7'))
828 self.assertEqual(lb.get(5, 0), ())
829 self.assertEqual(lb.get(0, 0), ('el0',))
830 self.assertRaises(TclError, lb.get, 'noindex')
831 self.assertRaises(TclError, lb.get, None)
832 self.assertRaises(TypeError, lb.get)
833 self.assertRaises(TclError, lb.get, 'end', 'noindex')
834 self.assertRaises(TypeError, lb.get, 1, 2, 3)
835 self.assertRaises(TclError, lb.get, 2.4)
836
837
838 @add_standard_options(PixelSizeTests, StandardOptionsTests)
839 class ScaleTest(AbstractWidgetTest, unittest.TestCase):
840 OPTIONS = (
841 'activebackground', 'background', 'bigincrement', 'borderwidth',
842 'command', 'cursor', 'digits', 'font', 'foreground', 'from',
843 'highlightbackground', 'highlightcolor', 'highlightthickness',
844 'label', 'length', 'orient', 'relief',
845 'repeatdelay', 'repeatinterval',
846 'resolution', 'showvalue', 'sliderlength', 'sliderrelief', 'state',
847 'takefocus', 'tickinterval', 'to', 'troughcolor', 'variable', 'width',
848 )
849 default_orient = 'vertical'
850
851 def create(self, **kwargs):
852 return tkinter.Scale(self.root, **kwargs)
853
854 def test_bigincrement(self):
855 widget = self.create()
856 self.checkFloatParam(widget, 'bigincrement', 12.4, 23.6, -5)
857
858 def test_digits(self):
859 widget = self.create()
860 self.checkIntegerParam(widget, 'digits', 5, 0)
861
862 def test_from(self):
863 widget = self.create()
864 self.checkFloatParam(widget, 'from', 100, 14.9, 15.1, conv=round)
865
866 def test_label(self):
867 widget = self.create()
868 self.checkParam(widget, 'label', 'any string')
869 self.checkParam(widget, 'label', '')
870
871 def test_length(self):
872 widget = self.create()
873 self.checkPixelsParam(widget, 'length', 130, 131.2, 135.6, '5i')
874
875 def test_resolution(self):
876 widget = self.create()
877 self.checkFloatParam(widget, 'resolution', 4.2, 0, 6.7, -2)
878
879 def test_showvalue(self):
880 widget = self.create()
881 self.checkBooleanParam(widget, 'showvalue')
882
883 def test_sliderlength(self):
884 widget = self.create()
885 self.checkPixelsParam(widget, 'sliderlength',
886 10, 11.2, 15.6, -3, '3m')
887
888 def test_sliderrelief(self):
889 widget = self.create()
890 self.checkReliefParam(widget, 'sliderrelief')
891
892 def test_tickinterval(self):
893 widget = self.create()
894 self.checkFloatParam(widget, 'tickinterval', 1, 4.3, 7.6, 0,
895 conv=round)
896 self.checkParam(widget, 'tickinterval', -2, expected=2,
897 conv=round)
898
899 def test_to(self):
900 widget = self.create()
901 self.checkFloatParam(widget, 'to', 300, 14.9, 15.1, -10,
902 conv=round)
903
904
905 @add_standard_options(PixelSizeTests, StandardOptionsTests)
906 class ScrollbarTest(AbstractWidgetTest, unittest.TestCase):
907 OPTIONS = (
908 'activebackground', 'activerelief',
909 'background', 'borderwidth',
910 'command', 'cursor', 'elementborderwidth',
911 'highlightbackground', 'highlightcolor', 'highlightthickness',
912 'jump', 'orient', 'relief',
913 'repeatdelay', 'repeatinterval',
914 'takefocus', 'troughcolor', 'width',
915 )
916 _conv_pixels = staticmethod(int_round)
917 _stringify = True
918 default_orient = 'vertical'
919
920 def create(self, **kwargs):
921 return tkinter.Scrollbar(self.root, **kwargs)
922
923 def test_activerelief(self):
924 widget = self.create()
925 self.checkReliefParam(widget, 'activerelief')
926
927 def test_elementborderwidth(self):
928 widget = self.create()
929 self.checkPixelsParam(widget, 'elementborderwidth', 4.3, 5.6, -2, '1m')
930
931 def test_orient(self):
932 widget = self.create()
933 self.checkEnumParam(widget, 'orient', 'vertical', 'horizontal',
934 errmsg='bad orientation "{}": must be vertical or horizontal')
935
936 def test_activate(self):
937 sb = self.create()
938 for e in ('arrow1', 'slider', 'arrow2'):
939 sb.activate(e)
940 sb.activate('')
941 self.assertRaises(TypeError, sb.activate)
942 self.assertRaises(TypeError, sb.activate, 'arrow1', 'arrow2')
943
944 def test_set(self):
945 sb = self.create()
946 sb.set(0.2, 0.4)
947 self.assertEqual(sb.get(), (0.2, 0.4))
948 self.assertRaises(TclError, sb.set, 'abc', 'def')
949 self.assertRaises(TclError, sb.set, 0.6, 'def')
950 self.assertRaises(TclError, sb.set, 0.6, None)
951 self.assertRaises(TclError, sb.set, 0.6)
952 self.assertRaises(TclError, sb.set, 0.6, 0.7, 0.8)
953
954
955 @add_standard_options(StandardOptionsTests)
956 class PanedWindowTest(AbstractWidgetTest, unittest.TestCase):
957 OPTIONS = (
958 'background', 'borderwidth', 'cursor',
959 'handlepad', 'handlesize', 'height',
960 'opaqueresize', 'orient',
961 'proxybackground', 'proxyborderwidth', 'proxyrelief',
962 'relief',
963 'sashcursor', 'sashpad', 'sashrelief', 'sashwidth',
964 'showhandle', 'width',
965 )
966 default_orient = 'horizontal'
967
968 def create(self, **kwargs):
969 return tkinter.PanedWindow(self.root, **kwargs)
970
971 def test_handlepad(self):
972 widget = self.create()
973 self.checkPixelsParam(widget, 'handlepad', 5, 6.4, 7.6, -3, '1m')
974
975 def test_handlesize(self):
976 widget = self.create()
977 self.checkPixelsParam(widget, 'handlesize', 8, 9.4, 10.6, -3, '2m',
978 conv=noconv)
979
980 def test_height(self):
981 widget = self.create()
982 self.checkPixelsParam(widget, 'height', 100, 101.2, 102.6, -100, 0, '1i',
983 conv=noconv)
984
985 def test_opaqueresize(self):
986 widget = self.create()
987 self.checkBooleanParam(widget, 'opaqueresize')
988
989 @requires_tcl(8, 6, 5)
990 def test_proxybackground(self):
991 widget = self.create()
992 self.checkColorParam(widget, 'proxybackground')
993
994 @requires_tcl(8, 6, 5)
995 def test_proxyborderwidth(self):
996 widget = self.create()
997 self.checkPixelsParam(widget, 'proxyborderwidth',
998 0, 1.3, 2.9, 6, -2, '10p',
999 conv=noconv)
1000
1001 @requires_tcl(8, 6, 5)
1002 def test_proxyrelief(self):
1003 widget = self.create()
1004 self.checkReliefParam(widget, 'proxyrelief')
1005
1006 def test_sashcursor(self):
1007 widget = self.create()
1008 self.checkCursorParam(widget, 'sashcursor')
1009
1010 def test_sashpad(self):
1011 widget = self.create()
1012 self.checkPixelsParam(widget, 'sashpad', 8, 1.3, 2.6, -2, '2m')
1013
1014 def test_sashrelief(self):
1015 widget = self.create()
1016 self.checkReliefParam(widget, 'sashrelief')
1017
1018 def test_sashwidth(self):
1019 widget = self.create()
1020 self.checkPixelsParam(widget, 'sashwidth', 10, 11.1, 15.6, -3, '1m',
1021 conv=noconv)
1022
1023 def test_showhandle(self):
1024 widget = self.create()
1025 self.checkBooleanParam(widget, 'showhandle')
1026
1027 def test_width(self):
1028 widget = self.create()
1029 self.checkPixelsParam(widget, 'width', 402, 403.4, 404.6, -402, 0, '5i',
1030 conv=noconv)
1031
1032 def create2(self):
1033 p = self.create()
1034 b = tkinter.Button(p)
1035 c = tkinter.Button(p)
1036 p.add(b)
1037 p.add(c)
1038 return p, b, c
1039
1040 def test_paneconfigure(self):
1041 p, b, c = self.create2()
1042 self.assertRaises(TypeError, p.paneconfigure)
1043 d = p.paneconfigure(b)
1044 self.assertIsInstance(d, dict)
1045 for k, v in d.items():
1046 self.assertEqual(len(v), 5)
1047 self.assertEqual(v, p.paneconfigure(b, k))
1048 self.assertEqual(v[4], p.panecget(b, k))
1049
1050 def check_paneconfigure(self, p, b, name, value, expected, stringify=False):
1051 conv = lambda x: x
1052 if not self.wantobjects or stringify:
1053 expected = str(expected)
1054 if self.wantobjects and stringify:
1055 conv = str
1056 p.paneconfigure(b, **{name: value})
1057 self.assertEqual(conv(p.paneconfigure(b, name)[4]), expected)
1058 self.assertEqual(conv(p.panecget(b, name)), expected)
1059
1060 def check_paneconfigure_bad(self, p, b, name, msg):
1061 with self.assertRaisesRegexp(TclError, msg):
1062 p.paneconfigure(b, **{name: 'badValue'})
1063
1064 def test_paneconfigure_after(self):
1065 p, b, c = self.create2()
1066 self.check_paneconfigure(p, b, 'after', c, str(c))
1067 self.check_paneconfigure_bad(p, b, 'after',
1068 'bad window path name "badValue"')
1069
1070 def test_paneconfigure_before(self):
1071 p, b, c = self.create2()
1072 self.check_paneconfigure(p, b, 'before', c, str(c))
1073 self.check_paneconfigure_bad(p, b, 'before',
1074 'bad window path name "badValue"')
1075
1076 def test_paneconfigure_height(self):
1077 p, b, c = self.create2()
1078 self.check_paneconfigure(p, b, 'height', 10, 10,
1079 stringify=get_tk_patchlevel() < (8, 5, 11))
1080 self.check_paneconfigure_bad(p, b, 'height',
1081 'bad screen distance "badValue"')
1082
1083 @requires_tcl(8, 5)
1084 def test_paneconfigure_hide(self):
1085 p, b, c = self.create2()
1086 self.check_paneconfigure(p, b, 'hide', False, 0)
1087 self.check_paneconfigure_bad(p, b, 'hide',
1088 'expected boolean value but got "badValue"')
1089
1090 def test_paneconfigure_minsize(self):
1091 p, b, c = self.create2()
1092 self.check_paneconfigure(p, b, 'minsize', 10, 10)
1093 self.check_paneconfigure_bad(p, b, 'minsize',
1094 'bad screen distance "badValue"')
1095
1096 def test_paneconfigure_padx(self):
1097 p, b, c = self.create2()
1098 self.check_paneconfigure(p, b, 'padx', 1.3, 1)
1099 self.check_paneconfigure_bad(p, b, 'padx',
1100 'bad screen distance "badValue"')
1101
1102 def test_paneconfigure_pady(self):
1103 p, b, c = self.create2()
1104 self.check_paneconfigure(p, b, 'pady', 1.3, 1)
1105 self.check_paneconfigure_bad(p, b, 'pady',
1106 'bad screen distance "badValue"')
1107
1108 def test_paneconfigure_sticky(self):
1109 p, b, c = self.create2()
1110 self.check_paneconfigure(p, b, 'sticky', 'nsew', 'nesw')
1111 self.check_paneconfigure_bad(p, b, 'sticky',
1112 'bad stickyness value "badValue": must '
1113 'be a string containing zero or more of '
1114 'n, e, s, and w')
1115
1116 @requires_tcl(8, 5)
1117 def test_paneconfigure_stretch(self):
1118 p, b, c = self.create2()
1119 self.check_paneconfigure(p, b, 'stretch', 'alw', 'always')
1120 self.check_paneconfigure_bad(p, b, 'stretch',
1121 'bad stretch "badValue": must be '
1122 'always, first, last, middle, or never')
1123
1124 def test_paneconfigure_width(self):
1125 p, b, c = self.create2()
1126 self.check_paneconfigure(p, b, 'width', 10, 10,
1127 stringify=get_tk_patchlevel() < (8, 5, 11))
1128 self.check_paneconfigure_bad(p, b, 'width',
1129 'bad screen distance "badValue"')
1130
1131
1132 @add_standard_options(StandardOptionsTests)
1133 class MenuTest(AbstractWidgetTest, unittest.TestCase):
1134 OPTIONS = (
1135 'activebackground', 'activeborderwidth', 'activeforeground',
1136 'background', 'borderwidth', 'cursor',
1137 'disabledforeground', 'font', 'foreground',
1138 'postcommand', 'relief', 'selectcolor', 'takefocus',
1139 'tearoff', 'tearoffcommand', 'title', 'type',
1140 )
1141 _conv_pixels = noconv_meth
1142
1143 def create(self, **kwargs):
1144 return tkinter.Menu(self.root, **kwargs)
1145
1146 def test_postcommand(self):
1147 widget = self.create()
1148 self.checkCommandParam(widget, 'postcommand')
1149
1150 def test_tearoff(self):
1151 widget = self.create()
1152 self.checkBooleanParam(widget, 'tearoff')
1153
1154 def test_tearoffcommand(self):
1155 widget = self.create()
1156 self.checkCommandParam(widget, 'tearoffcommand')
1157
1158 def test_title(self):
1159 widget = self.create()
1160 self.checkParam(widget, 'title', 'any string')
1161
1162 def test_type(self):
1163 widget = self.create()
1164 self.checkEnumParam(widget, 'type',
1165 'normal', 'tearoff', 'menubar')
1166
1167 def test_entryconfigure(self):
1168 m1 = self.create()
1169 m1.add_command(label='test')
1170 self.assertRaises(TypeError, m1.entryconfigure)
1171 with self.assertRaisesRegexp(TclError, 'bad menu entry index "foo"'):
1172 m1.entryconfigure('foo')
1173 d = m1.entryconfigure(1)
1174 self.assertIsInstance(d, dict)
1175 for k, v in d.items():
1176 self.assertIsInstance(k, str)
1177 self.assertIsInstance(v, tuple)
1178 self.assertEqual(len(v), 5)
1179 self.assertEqual(v[0], k)
1180 self.assertEqual(m1.entrycget(1, k), v[4])
1181 m1.destroy()
1182
1183 def test_entryconfigure_label(self):
1184 m1 = self.create()
1185 m1.add_command(label='test')
1186 self.assertEqual(m1.entrycget(1, 'label'), 'test')
1187 m1.entryconfigure(1, label='changed')
1188 self.assertEqual(m1.entrycget(1, 'label'), 'changed')
1189
1190 def test_entryconfigure_variable(self):
1191 m1 = self.create()
1192 v1 = tkinter.BooleanVar(self.root)
1193 v2 = tkinter.BooleanVar(self.root)
1194 m1.add_checkbutton(variable=v1, onvalue=True, offvalue=False,
1195 label='Nonsense')
1196 self.assertEqual(str(m1.entrycget(1, 'variable')), str(v1))
1197 m1.entryconfigure(1, variable=v2)
1198 self.assertEqual(str(m1.entrycget(1, 'variable')), str(v2))
1199
1200
1201 @add_standard_options(PixelSizeTests, StandardOptionsTests)
1202 class MessageTest(AbstractWidgetTest, unittest.TestCase):
1203 OPTIONS = (
1204 'anchor', 'aspect', 'background', 'borderwidth',
1205 'cursor', 'font', 'foreground',
1206 'highlightbackground', 'highlightcolor', 'highlightthickness',
1207 'justify', 'padx', 'pady', 'relief',
1208 'takefocus', 'text', 'textvariable', 'width',
1209 )
1210 _conv_pad_pixels = noconv_meth
1211
1212 def create(self, **kwargs):
1213 return tkinter.Message(self.root, **kwargs)
1214
1215 def test_aspect(self):
1216 widget = self.create()
1217 self.checkIntegerParam(widget, 'aspect', 250, 0, -300)
1218
1219
1220 tests_gui = [
1221 ButtonTest, CanvasTest, CheckbuttonTest, EntryTest,
1222 FrameTest, LabelFrameTest,LabelTest, ListboxTest,
1223 MenubuttonTest, MenuTest, MessageTest, OptionMenuTest,
1224 PanedWindowTest, RadiobuttonTest, ScaleTest, ScrollbarTest,
1225 SpinboxTest, TextTest, ToplevelTest,
1226 ]
1227
1228 if __name__ == '__main__':
1229 run_unittest(*tests_gui)