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