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