[英]Tkinter and Twisted - creating a deamonic reactor in Python#
我正在嘗試使用tkinter並在python 3中進行扭曲。我遵循了這個答案,即Twisted和Tkinter的線程化 ,它使我可以運行它。
但是問題在於,當代碼崩潰或被用戶關閉時,反應堆不會停止。 我如何設置它,以便反應堆是tkinter程序的守護進程。 到目前為止,我已經嘗試在關閉tkinter gui時使其關閉反應堆,這不是理想的行為(因為我想在任何故障情況下都關閉),但是如果可以的話,這將是第一步上班。
我的代碼如下
from twisted.internet import reactor, protocol
import tkinter as tk
import tksupport
import GUI
def on_closing():
reactor.stop()
tksupport.uninstall()
root.destroy()
root = GUI.BruGUI()
tksupport.install(root)
root.protocol("WM_DELETE_WINDOW", on_closing)
reactor.run()
tksupport代碼來自上一個鏈接。
一種簡單的方法是將其放在try / except塊中,但這通常只是一種解決方法:
try:
from twisted.internet import reactor, protocol
import tkinter as tk
import tksupport
import GUI
def on_closing():
reactor.stop()
tksupport.uninstall()
root.destroy()
root = GUI.BruGUI()
tksupport.install(root)
root.protocol("WM_DELETE_WINDOW", on_closing)
reactor.run()
except:
reactor.stop()
tksupport.uninstall()
root.destroy()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.