1 # Tests for basic Tkinter widgets.
9 if Tkinter.TkVersion >= 8.0:
23 (Test.num_options, (), button_num),
24 ('text', 'Hello World'),
25 ('background', 'lightsteelblue1'),
26 ('foreground', 'seagreen4'),
27 ('command', Test.callback),
31 testData = testData + ((c, ((tests, {}),)),)
36 (Test.num_options, (), 27),
37 ('background', 'aliceblue'),
38 (c.create_oval, (100, 100, 200, 200),
39 {'fill' : 'lightsteelblue1', 'tags' : 'circle'}, 1),
40 (c.create_rectangle, (200, 100, 300, 200),
41 {'fill' : 'lightsteelblue2', 'tags' : 'square'}, 2),
42 (c.create_text, (0, 200),
43 {'text' : 'Hello, world', 'tags' : 'words', 'anchor' : 'w'}, 3),
44 (c.addtag_withtag, ('lightsteelblue1', 'circle')),
45 (c.bbox, ('circle', 'square'), (99, 99, 301, 201)),
46 (c.tag_bind, ('circle', '<1>', Test.callback)),
47 (c.tag_bind, 'circle', '<Button-1>'),
48 (c.tag_unbind, ('circle', '<1>')),
49 (c.canvasx, 100, 100.0),
50 (c.canvasy, 100, 100.0),
51 (c.coords, 'circle', [100.0, 100.0, 200.0, 200.0]),
52 (c.coords, ('circle', 0, 0, 300, 300), []),
53 (c.coords, 'circle', [0.0, 0.0, 300.0, 300.0]),
54 (c.find_withtag, 'lightsteelblue1', (1,)),
55 (c.focus, 'circle', ''),
56 (c.gettags, 'circle', ('circle', 'lightsteelblue1')),
57 (c.icursor, ('words', 7)),
58 (c.index, ('words', 'insert'), 7),
59 (c.insert, ('words', 'insert', 'cruel ')),
60 (c.itemconfigure, 'circle', {'fill': 'seagreen4'}),
61 (c.itemcget, ('circle', 'fill'), 'seagreen4'),
63 (c.move, ('square', -50, -50)),
64 (c.tkraise, ('words', 'circle')),
65 (c.scale, ('circle', 150, 150, 1.0, 0.5)),
66 (c.select_from, ('words', 0)),
67 (c.select_to, ('words', 'end')),
69 (c.type, 'circle', 'oval'),
70 (c.dtag, 'lightsteelblue1'),
72 testData = testData + ((c, ((tests, {}),)),)
74 c = Tkinter.Checkbutton
77 (Test.num_options, (), 36),
78 ('text', 'Hello World'),
79 ('background', 'lightsteelblue1'),
80 ('foreground', 'seagreen4'),
81 ('command', Test.callback),
85 testData = testData + ((c, ((tests, {}),)),)
90 (Test.num_options, (), 28),
91 ('background', 'lightsteelblue1'),
92 (c.insert, ('insert', 'Hello, Brian!')),
95 (c.insert, ('insert', 'world')),
96 (c.get, (), 'Hello, world!'),
97 (c.index, 'insert', 12),
98 (c.selection_from, 7),
99 (c.selection_to, '12'),
101 testData = testData + ((c, ((tests, {}),)),)
106 (Test.num_options, (), frame_num),
107 ('background', 'lightsteelblue1'),
110 ('background', 'lightsteelblue1'),
112 testData = testData + ((c, ((tests, {}),)),)
117 (Test.num_options, (), 25),
118 ('text', 'Hello World'),
119 ('background', 'lightsteelblue1'),
120 ('foreground', 'seagreen4'),
121 ('image', Test.earthris),
123 testData = testData + ((c, ((tests, {}),)),)
128 (Test.num_options, (), 23),
129 ('background', 'lightsteelblue1'),
130 ('foreground', 'seagreen4'),
131 (c.insert, (0, 'ABC', 'DEF', 'GHI', 'XXXXXXXXXXXX')),
133 (c.select_set, (2, 3)),
134 (c.curselection, (), ('2', '3')),
137 (c.get, (0, 1), ('ABC', 'GHI')),
143 testData = testData + ((c, ((tests, {}),)),)
147 (Test.num_options, (), menu_num),
148 ('background', 'lightsteelblue1'),
149 ('foreground', 'seagreen4'),
151 {'background': 'lightsteelblue2', 'label': 'Hello World'}),
152 (c.add_checkbutton, (),
153 {'background': 'lightsteelblue2', 'label': 'Charm'}),
154 (c.post, (100, 100)),
156 (c.entryconfigure, 'Hello World', {'background': 'aliceblue'}),
157 (c.entrycget, ('Hello World', 'background'), 'aliceblue'),
161 (c.insert_radiobutton, 'Charm',
162 {'background': 'lightsteelblue2', 'label': 'Niceness',
163 'command': Test.callback}),
164 (c.invoke, 'Niceness', '1'),
166 (c.type, 'Hello World', 'command'),
167 (c.yposition, 'Hello World', 2),
170 testData = testData + ((c, ((tests, {}),)),)
172 c = Tkinter.Menubutton
175 (Test.num_options, (), menubutton_num),
176 ('text', 'Hello World'),
177 ('background', 'lightsteelblue1'),
178 ('foreground', 'seagreen4'),
180 testData = testData + ((c, ((tests, {}),)),)
185 (Test.num_options, (), 21),
186 ('text', 'Hello World'),
187 ('background', 'lightsteelblue1'),
188 ('foreground', 'seagreen4'),
189 ('text', 'Hello\nCruel Cruel World'),
190 ('borderwidth', 100),
191 ('justify', 'center'),
192 ('justify', 'right'),
195 testData = testData + ((c, ((tests, {}),)),)
197 c = Tkinter.Radiobutton
200 (Test.num_options, (), 35),
201 ('text', 'Hello World'),
202 ('value', 'Foo Bar'),
203 ('variable', Test.stringvar),
204 ('background', 'lightsteelblue1'),
205 ('foreground', 'seagreen4'),
206 ('text', 'Hello\nCruel Cruel World'),
207 ('command', Test.callback),
209 (Test.stringvar.get, (), 'Foo Bar'),
213 (Test.stringvar.get, (), ''),
215 testData = testData + ((c, ((tests, {}),)),)
220 (Test.num_options, (), 33),
222 ('orient', 'horizontal'),
225 ('variable', Test.floatvar),
226 ('background', 'lightsteelblue1'),
227 ('foreground', 'seagreen4'),
228 ('command', Test.callback1),
231 (c.get, 123, 'TypeError: too many arguments; expected 1, got 2'),
233 testData = testData + ((c, ((tests, {}),)),)
235 c = Tkinter.Scrollbar
237 (c.pack, (), {'fill': 'x'}),
238 (Test.num_options, (), 20),
239 ('orient', 'horizontal'),
240 (Test.set_geom, (300, 50)),
242 ('background', 'lightsteelblue1'),
243 ('troughcolor', 'aliceblue'),
244 (c.get, (), (0.3, 0.7)),
245 (c.activate, 'slider'),
247 (c.delta, (0, 0), 0),
248 (c.fraction, (0, 0), 0),
250 testData = testData + ((c, ((tests, {}),)),)
255 (Test.num_options, (), 35),
256 ('background', 'lightsteelblue1'),
257 (c.insert, ('end', 'This little piggy is bold.', 'bold', '\n')),
258 (c.insert, ('end', 'This little piggy is in green.', 'green', '\n')),
259 (c.insert, ('end', 'This line is a mistake.\n')),
260 (c.insert, ('end', 'This little piggy is crossed out.', 'overstrike', '\n')),
261 (c.insert, ('end', 'This little piggy is raised.', 'raised', '\n')),
262 (c.insert, ('end', 'This little piggy is underlined.', 'underline', '\n')),
263 (c.tag_configure, 'bold', {'font': Test.font['variable']}),
264 (c.tag_configure, 'green', {'background': 'seagreen1'}),
265 (c.tag_configure, 'overstrike', {'overstrike': 1}),
266 (c.tag_configure, 'raised',
267 {'background': 'aliceblue', 'borderwidth': 2, 'relief': 'raised'}),
268 (c.tag_configure, 'underline', {'underline': 1}),
269 (c.compare, ('2.0', '<', 'end'), 1),
270 (c.delete, ('3.0', '4.0')),
271 (c.get, ('1.0', '1.4'), 'This'),
272 (c.index, 'end', '7.0'),
273 (c.mark_set, ('my_mark', '4.9')),
274 (c.mark_gravity, ('my_mark', 'right'), ''),
275 (c.mark_gravity, 'my_mark', 'right'),
276 (c.mark_names, (), ('my_mark', 'insert', 'current')),
277 (c.mark_unset, 'my_mark'),
278 (c.insert, ('end', '\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n')),
279 (c.insert, ('end', 'This is the last line.')),
280 (c.scan_mark, (0, 20)),
281 (c.scan_dragto, (0, 0)),
282 (c.scan_dragto, (0, 20)),
283 (c.tag_add, ('green', '1.0', '1.4')),
284 (c.tag_cget, ('raised', 'background'), 'aliceblue'),
285 (c.tag_lower, 'green'),
287 ('green', 'sel', 'bold', 'overstrike', 'raised', 'underline')),
288 (c.tag_nextrange, ('raised', '0.0'), ('4.0', '4.28')),
289 (c.tag_raise, 'green'),
290 (c.tag_ranges, 'green', ('1.0', '1.4', '2.0', '2.30')),
291 (c.tag_remove, ('green', '1.0', '1.4')),
292 (c.tag_ranges, 'green', ('2.0', '2.30')),
293 (c.tag_delete, 'green'),
294 (c.search, ('Gre.n', '0.0'), {'regexp': 1, 'nocase': 1}, '2.24'),
295 (c.search, ('Gre.n', '3.0', 'end'), {'regexp': 1, 'nocase': 1}, ''),
299 testData = testData + ((c, ((tests, {}),)),)
301 #=============================================================================
305 def _makeGridButtons():
306 w = Test.currentWidget()
307 b1 = Tkinter.Button(w, text = 'Button 1')
308 b2 = Tkinter.Button(w, text = 'Button 2')
309 b3 = Tkinter.Button(w, text = 'Button 3')
310 b4 = Tkinter.Button(w, text = 'Button 4')
311 b5 = Tkinter.Button(w, text = 'Button 5')
312 b6 = Tkinter.Button(w, text = 'Button 6')
313 b7 = Tkinter.Button(w, text = 'Button 7')
314 b8 = Tkinter.Button(w, text = 'Button 8')
316 b1.grid(column=0, row=0)
317 b2.grid(column=1, row=0)
318 b3.grid(column=2, row=0, ipadx=50, ipady=50, padx=50, pady=50, sticky='nsew')
319 b4.grid(column=3, row=0)
320 b5.grid(column=0, row=1)
321 b6.grid(column=2, row=1, columnspan=2, rowspan=2, sticky='nsew')
322 b7.grid(column=0, row=2)
323 b8.grid(column=0, row=3, columnspan=4, padx=50, sticky='ew')
325 def _checkGridSlaves():
326 w = Test.currentWidget()
327 return len(w.grid_slaves())
329 def _checkGridInfo():
330 w = Test.currentWidget()
331 b8 = w.grid_slaves(column=0, row=3)[0]
332 info = b8.grid_info()
335 for key, value in info.items():
341 def _checkGridForget():
342 w = Test.currentWidget()
343 b8 = w.grid_slaves(column=0, row=3)[0]
347 # The -pad grid option was added in Tk 4.2.
348 # Could not do columnconfigure(0) before Tk 4.2.
349 if Tkinter.TkVersion >= 4.2:
350 padTest = {'pad': 25}
351 colTest = {'minsize': 100, 'pad': 25, 'weight': 1}
352 rowTest = {'minsize': 100, 'pad': 0, 'weight': 1}
354 padTest = {'minsize': 100}
355 colTest = 'TclError: wrong # args: should be "grid columnconfigure master index ?-option value...?"'
356 rowTest = 'TclError: wrong # args: should be "grid rowconfigure master index ?-option value...?"'
360 (c.pack, (), {'fill': 'both', 'expand': 1}),
361 (_makeGridButtons, ()),
362 # (c.grid_bbox, (1, 2), (85, 268, 85, 34)),
363 (c.grid_columnconfigure, (0, 'minsize'), 0),
364 (c.grid_columnconfigure, (0, 'weight'), 0),
365 (c.grid_columnconfigure, 0, {'minsize': 100, 'weight': 1}),
366 (c.grid_columnconfigure, 0, padTest),
367 (c.grid_columnconfigure, 0, {}, colTest),
368 (c.grid_columnconfigure, (0, 'minsize'), 100),
369 (c.grid_columnconfigure, (0, 'weight'), 1),
370 (c.location, (200, 100), (2, 0)),
371 (c.grid_propagate, (), 1),
372 (c.grid_propagate, 0),
373 (c.grid_propagate, (), 0),
374 (c.grid_rowconfigure, (0, 'minsize'), 0),
375 (c.grid_rowconfigure, (0, 'weight'), 0),
376 (c.grid_rowconfigure, 0, {'minsize': 100, 'weight': 1}),
377 (c.grid_rowconfigure, 0, {}, rowTest),
378 (c.grid_size, (), (4, 4)),
379 (_checkGridSlaves, (), 8),
380 (_checkGridInfo, (), {}, {'column': '0', 'columnspan': '4',
381 'ipadx': '0', 'ipady': '0', 'padx': '50', 'pady': '0',
382 'row': '3', 'rowspan': '1', 'sticky': 'ew',
384 (_checkGridForget, (), (4, 3)),
385 (_checkGridSlaves, (), 7),
388 testData = testData + ((c, ((tests, {}),)),)
390 if __name__ == '__main__':
393 Test.runTests(testData)