1import os 2import unittest 3from test import test_support 4 5# Skip this test if _tkinter wasn't built or gui resource is not available. 6test_support.import_module('_tkinter') 7test_support.requires('gui') 8 9this_dir = os.path.dirname(os.path.abspath(__file__)) 10lib_tk_test = os.path.abspath(os.path.join(this_dir, os.path.pardir, 11 'lib-tk', 'test')) 12 13with test_support.DirsOnSysPath(lib_tk_test): 14 import runtktests 15 16import Tkinter as tkinter 17import ttk 18from _tkinter import TclError 19 20root = None 21try: 22 root = tkinter.Tk() 23 button = ttk.Button(root) 24 button.destroy() 25 del button 26except TclError as msg: 27 # assuming ttk is not available 28 raise unittest.SkipTest("ttk not available: %s" % msg) 29finally: 30 if root is not None: 31 root.destroy() 32 del root 33 34def test_main(): 35 with test_support.DirsOnSysPath(lib_tk_test): 36 test_support.run_unittest( 37 *runtktests.get_tests(text=False, packages=['test_ttk'])) 38 39if __name__ == '__main__': 40 test_main() 41