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