2009-11-12 136 views
1

我正在運行一個應用程序,使用twisted和tkinter將結果發送到服務器,等待服務器發回確認信息,然後退出。所以,我用退出的功能是這樣的:退出時扭曲/ tkinter程序崩潰

def term(): 
    '''To end the program''' 
    reactor.stop() 
    root.quit() 
    root.destroy() 

然後,這是出廠時設置的,並要求在協議的dataReceived功能。我運行它,程序運行良好,甚至把必要的數據和關閉,但它也給我下面的錯誤報告:

Unhandled error in Deferred: 
Traceback (most recent call last): 
    File "D:\Python25\Lib\site-packages\twisted\internet\base.py", line 1128, in run 
    self.mainLoop() 
    File "D:\Python25\Lib\site-packages\twisted\internet\base.py", line 1137, in mainLoop 
    self.runUntilCurrent() 
    File "D:\Python25\Lib\site-packages\twisted\internet\base.py", line 757, in runUntilCurrent 
    call.func(*call.args, **call.kw) 
    File "D:\Python25\Lib\site-packages\twisted\internet\task.py", line 114, in __call__ 
    d = defer.maybeDeferred(self.f, *self.a, **self.kw) 
--- <exception caught here> --- 
    File "D:\Python25\Lib\site-packages\twisted\internet\defer.py", line 106, in maybeDeferred 
    result = f(*args, **kw) 
    File "D:\Python25\lib\lib-tk\Tkinter.py", line 917, in update 
    self.tk.call('update') 
_tkinter.TclError: can't invoke "update" command: application has been destroyed 

有誰知道爲什麼嗎?

回答

1

您只需撥打reactor.stop退出:root.quit()root.destroy()調用是多餘的。考慮一下運行Twisted和Tk三秒鐘然後退出的簡短例子:

import Tkinter 
from twisted.internet import tksupport 

root = Tkinter.Tk() 
tksupport.install(root) 

from twisted.internet import reactor 
reactor.callLater(3, reactor.stop) 
reactor.run() 
+0

它不再給我問題了,謝謝。 – Nikwin 2009-11-12 16:03:44