Home | History | Annotate | Download | only in test_ttk
      1 import Tkinter
      2 
      3 def get_tk_root():
      4     try:
      5         root = Tkinter._default_root
      6     except AttributeError:
      7         # it is possible to disable default root in Tkinter, although
      8         # I haven't seen people doing it (but apparently someone did it
      9         # here).
     10         root = None
     11 
     12     if root is None:
     13         # create a new master only if there isn't one already
     14         root = Tkinter.Tk()
     15 
     16     return root
     17 
     18 def root_deiconify():
     19     root = get_tk_root()
     20     root.deiconify()
     21 
     22 def root_withdraw():
     23     root = get_tk_root()
     24     root.withdraw()
     25 
     26 
     27 def simulate_mouse_click(widget, x, y):
     28     """Generate proper events to click at the x, y position (tries to act
     29     like an X server)."""
     30     widget.event_generate('<Enter>', x=0, y=0)
     31     widget.event_generate('<Motion>', x=x, y=y)
     32     widget.event_generate('<ButtonPress-1>', x=x, y=y)
     33     widget.event_generate('<ButtonRelease-1>', x=x, y=y)
     34