Debian Codegraph @

docs/core/examples/tkinterdemo.py

raw
1 #!/usr/bin/env python
2
3 # Copyright (c) Twisted Matrix Laboratories.
4 # See LICENSE for details.
5
6
7 """
8 An example of using Twisted with Tkinter.
9 Displays a frame with buttons that responds to mouse clicks.
10
11 Run this example by typing in:
12 python tkinterdemo.py
13 """
14
15
16 from tkinter import LEFT, Button, Frame, Tk
17
18 from twisted.internet import reactor, tksupport
19
20
21 class App:
22 def onQuit(self):
23 print("Quit!")
24 reactor.stop()
25
26 def onButton(self):
27 print("Hello!")
28
29 def __init__(self, master):
30 frame = Frame(master)
31 frame.pack()
32
33 q = Button(frame, text="Quit!", command=self.onQuit)
34 b = Button(frame, text="Hello!", command=self.onButton)
35
36 q.pack(side=LEFT)
37 b.pack(side=LEFT)
38
39
40 if __name__ == "__main__":
41 root = Tk()
42 tksupport.install(root)
43 app = App(root)
44 reactor.run()