~ubuntu-branches/ubuntu/maverick/python3.1/maverick

« back to all changes in this revision

Viewing changes to Lib/tkinter/test/support.py

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2009-03-23 00:01:27 UTC
  • Revision ID: james.westby@ubuntu.com-20090323000127-5fstfxju4ufrhthq
Tags: upstream-3.1~a1+20090322
ImportĀ upstreamĀ versionĀ 3.1~a1+20090322

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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)