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