summaryrefslogtreecommitdiffstats
path: root/Lib/tkinter/test/support.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/tkinter/test/support.py')
-rw-r--r--Lib/tkinter/test/support.py51
1 files changed, 32 insertions, 19 deletions
diff --git a/Lib/tkinter/test/support.py b/Lib/tkinter/test/support.py
index 7ae0cbb..017681f 100644
--- a/Lib/tkinter/test/support.py
+++ b/Lib/tkinter/test/support.py
@@ -3,30 +3,43 @@ import tkinter
import unittest
from test.support import requires
-def get_tk_root():
- requires('gui') # raise exception if tk unavailable
- try:
- root = tkinter._default_root
- except AttributeError:
- # it is possible to disable default root in Tkinter, although
- # I haven't seen people doing it (but apparently someone did it
- # here).
- root = None
+class AbstractTkTest:
- if root is None:
- # create a new master only if there isn't one already
- root = tkinter.Tk()
+ @classmethod
+ def setUpClass(cls):
+ cls._old_support_default_root = tkinter._support_default_root
+ destroy_default_root()
+ tkinter.NoDefaultRoot()
+ cls.root = tkinter.Tk()
+ cls.wantobjects = cls.root.wantobjects()
+ # De-maximize main window.
+ # Some window managers can maximize new windows.
+ cls.root.wm_state('normal')
+ try:
+ cls.root.wm_attributes('-zoomed', False)
+ except tkinter.TclError:
+ pass
- return root
+ @classmethod
+ def tearDownClass(cls):
+ cls.root.destroy()
+ cls.root = None
+ tkinter._default_root = None
+ tkinter._support_default_root = cls._old_support_default_root
-def root_deiconify():
- root = get_tk_root()
- root.deiconify()
+ def setUp(self):
+ self.root.deiconify()
-def root_withdraw():
- root = get_tk_root()
- root.withdraw()
+ def tearDown(self):
+ for w in self.root.winfo_children():
+ w.destroy()
+ self.root.withdraw()
+def destroy_default_root():
+ if getattr(tkinter, '_default_root', None):
+ tkinter._default_root.update_idletasks()
+ tkinter._default_root.destroy()
+ tkinter._default_root = None
def simulate_mouse_click(widget, x, y):
"""Generate proper events to click at the x, y position (tries to act