File: tkinterdemo.py

package info (click to toggle)
twisted 25.5.0-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 20,560 kB
  • sloc: python: 203,171; makefile: 200; sh: 92; javascript: 36; xml: 31
file content (44 lines) | stat: -rw-r--r-- 862 bytes parent folder | download | duplicates (3)
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()