mirror of
				https://github.com/python/cpython.git
				synced 2025-10-26 11:14:33 +00:00 
			
		
		
		
	
		
			
				
	
	
		
			45 lines
		
	
	
	
		
			1.6 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			45 lines
		
	
	
	
		
			1.6 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
| import unittest
 | |
| import tkinter
 | |
| from tkinter import ttk
 | |
| from test import support
 | |
| 
 | |
| support.requires('gui')
 | |
| 
 | |
| class MiscTest(unittest.TestCase):
 | |
| 
 | |
|     def setUp(self):
 | |
|         self.root = ttk.setup_master()
 | |
| 
 | |
|     def test_tk_setPalette(self):
 | |
|         root = self.root
 | |
|         root.tk_setPalette('black')
 | |
|         self.assertEqual(root['background'], 'black')
 | |
|         root.tk_setPalette('white')
 | |
|         self.assertEqual(root['background'], 'white')
 | |
|         self.assertRaisesRegex(tkinter.TclError,
 | |
|                 '^unknown color name "spam"$',
 | |
|                 root.tk_setPalette, 'spam')
 | |
| 
 | |
|         root.tk_setPalette(background='black')
 | |
|         self.assertEqual(root['background'], 'black')
 | |
|         root.tk_setPalette(background='blue', highlightColor='yellow')
 | |
|         self.assertEqual(root['background'], 'blue')
 | |
|         self.assertEqual(root['highlightcolor'], 'yellow')
 | |
|         root.tk_setPalette(background='yellow', highlightColor='blue')
 | |
|         self.assertEqual(root['background'], 'yellow')
 | |
|         self.assertEqual(root['highlightcolor'], 'blue')
 | |
|         self.assertRaisesRegex(tkinter.TclError,
 | |
|                 '^unknown color name "spam"$',
 | |
|                 root.tk_setPalette, background='spam')
 | |
|         self.assertRaisesRegex(tkinter.TclError,
 | |
|                 '^must specify a background color$',
 | |
|                 root.tk_setPalette, spam='white')
 | |
|         self.assertRaisesRegex(tkinter.TclError,
 | |
|                 '^must specify a background color$',
 | |
|                 root.tk_setPalette, highlightColor='blue')
 | |
| 
 | |
| 
 | |
| tests_gui = (MiscTest, )
 | |
| 
 | |
| if __name__ == "__main__":
 | |
|     support.run_unittest(*tests_gui)
 | 
