Last active
November 17, 2023 09:27
-
-
Save nakagami/2d58fac16c03fd5dab8608d81a8826ad to your computer and use it in GitHub Desktop.
Python3 version of twisted tkinter support example tkinterdemo.py https://github.com/racker/python-twisted-core/blob/master/doc/examples/tkinterdemo.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 | |
""" | |
import os | |
from tkinter import Tk, Frame, Button, LEFT | |
from twisted.internet import reactor, tksupport | |
class App(object): | |
def onQuit(self): | |
print("Quit!") | |
reactor.stop() | |
os._exit(0) | |
def onButton(self): | |
print("Hello!") | |
def __init__(self, root): | |
root.protocol("WM_DELETE_WINDOW", self.onQuit) | |
frame = Frame(root) | |
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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment