Show More
@@ -1,36 +1,34 b'' | |||||
1 | #!/usr/bin/env python |
|
1 | #!/usr/bin/env python | |
2 | """Simple Tk example to manually test event loop integration. |
|
2 | """Simple Tk example to manually test event loop integration. | |
3 |
|
3 | |||
4 | This is meant to run tests manually in ipython as: |
|
4 | This is meant to run tests manually in ipython as: | |
5 |
|
5 | |||
6 | In [5]: %gui tk |
|
6 | In [5]: %gui tk | |
7 |
|
7 | |||
8 | In [6]: %run gui-tk.py |
|
8 | In [6]: %run gui-tk.py | |
9 | """ |
|
9 | """ | |
10 |
|
10 | |||
11 | try: |
|
11 | from tkinter import * | |
12 | from tkinter import * # Python 3 |
|
12 | ||
13 | except ImportError: |
|
|||
14 | from Tkinter import * # Python 2 |
|
|||
15 |
|
13 | |||
16 | class MyApp: |
|
14 | class MyApp: | |
17 |
|
15 | |||
18 | def __init__(self, root): |
|
16 | def __init__(self, root): | |
19 | frame = Frame(root) |
|
17 | frame = Frame(root) | |
20 | frame.pack() |
|
18 | frame.pack() | |
21 |
|
19 | |||
22 | self.button = Button(frame, text="Hello", command=self.hello_world) |
|
20 | self.button = Button(frame, text="Hello", command=self.hello_world) | |
23 | self.button.pack(side=LEFT) |
|
21 | self.button.pack(side=LEFT) | |
24 |
|
22 | |||
25 | def hello_world(self): |
|
23 | def hello_world(self): | |
26 | print("Hello World!") |
|
24 | print("Hello World!") | |
27 |
|
25 | |||
28 | root = Tk() |
|
26 | root = Tk() | |
29 |
|
27 | |||
30 | app = MyApp(root) |
|
28 | app = MyApp(root) | |
31 |
|
29 | |||
32 | try: |
|
30 | try: | |
33 | from IPython.lib.inputhook import enable_gui |
|
31 | from IPython.lib.inputhook import enable_gui | |
34 | enable_gui('tk', root) |
|
32 | enable_gui('tk', root) | |
35 | except ImportError: |
|
33 | except ImportError: | |
36 | root.mainloop() |
|
34 | root.mainloop() |
General Comments 0
You need to be logged in to leave comments.
Login now