[Twisted-Python] Can't quit a Tkinter application on MacOS X when using Twisted; fix? workaround?
I am trying to convert a cross-platform Python/Tkinter application to use Twisted and have run into a problem: at least on MacOS X I can no longer quit the application. I have appended a minimal script showing the problem. This is probably not an issue on unix and WIndows because I find I have to add my own Quit menu item anyway, so I can make it do what I like. But on MacOS X with Aqua Tcl/Tk that item is added by the system and its meaning appears to be hard-wired -- I suspect to it calls "quit" on Tk's mainloop, but I don't know. Any suggestion for a workaround would be most appreciated. Also if this is not a known issue I will file a bug report. -- Russell """Script showing failure-to-quit bug At least on MacOS XO 10.5.6 with twisted 8.2.0, python 2.5.2 (from python.org) and Aqua Tck/Tk 8.4.19 the File>Quit menu has no effect and typing ctrl-Q causes the menu to briefly highlight (as usual) but has no other effect. "" import Tkinter import twisted.internet.tksupport root = Tkinter.Tk() twisted.internet.tksupport.install(root) reactor = twisted.internet.reactor reactor.run()
In article <rowen-6F098F.12205007042009@news.gmane.org>, "Russell E. Owen" <rowen@u.washington.edu> wrote:
I am trying to convert a cross-platform Python/Tkinter application to use Twisted and have run into a problem: at least on MacOS X I can no longer quit the application. .... """Script showing failure-to-quit bug..."" import Tkinter import twisted.internet.tksupport
root = Tkinter.Tk() twisted.internet.tksupport.install(root) reactor = twisted.internet.reactor
reactor.run()
Just after posting this Kevin Walzer provided an answer. The Quit menu on MacOS X calls the tcl "exit" function. One can easily intercept this in Python/Tkinter using createcommand, e.g.: def myQuit(): reactor.stop() root.createcommand('exit', myQuit) -- Russell
On Tue, 07 Apr 2009 12:20:50 -0700, "Russell E. Owen" <rowen@u.washington.edu> wrote:
I am trying to convert a cross-platform Python/Tkinter application to use Twisted and have run into a problem: at least on MacOS X I can no longer quit the application.
I have appended a minimal script showing the problem.
The example omits this piece of code, recommended by the tksupport module docstring: root.protocol('WM_DELETE_WINDOW', reactor.stop) I know you posted another solution already, but I'm curious to know if the recommended fix works on OS X or if we should be recommended something else. Jean-Paul
In article <20090410160133.24697.1558421192.divmod.quotient.5786@henry.divmod.com>, Jean-Paul Calderone <exarkun@divmod.com> wrote:
On Tue, 07 Apr 2009 12:20:50 -0700, "Russell E. Owen" <rowen@u.washington.edu> wrote:
I am trying to convert a cross-platform Python/Tkinter application to use Twisted and have run into a problem: at least on MacOS X I can no longer quit the application.
I have appended a minimal script showing the problem.
The example omits this piece of code, recommended by the tksupport module docstring:
root.protocol('WM_DELETE_WINDOW', reactor.stop)
I know you posted another solution already, but I'm curious to know if the recommended fix works on OS X or if we should be recommended something else.
Jean-Paul
Yes, that is useful if your root window can be closed. (In my case it cannot.) The other fix mentioned handles the Quit menu and the Quit apple event. This fix handles the root window being closed killing the application properly. -- Russell
On Mon, 13 Apr 2009 13:49:58 -0700, "Russell E. Owen" <rowen@u.washington.edu> wrote:
In article <20090410160133.24697.1558421192.divmod.quotient.5786@henry.divmod.com>, Jean-Paul Calderone <exarkun@divmod.com> wrote:
On Tue, 07 Apr 2009 12:20:50 -0700, "Russell E. Owen" <rowen@u.washington.edu> wrote:
I am trying to convert a cross-platform Python/Tkinter application to use Twisted and have run into a problem: at least on MacOS X I can no longer quit the application.
I have appended a minimal script showing the problem.
The example omits this piece of code, recommended by the tksupport module docstring:
root.protocol('WM_DELETE_WINDOW', reactor.stop)
I know you posted another solution already, but I'm curious to know if the recommended fix works on OS X or if we should be recommended something else.
Jean-Paul
Yes, that is useful if your root window can be closed. (In my case it cannot.)
The other fix mentioned handles the Quit menu and the Quit apple event. This fix handles the root window being closed killing the application properly.
It sounds like we should expand the Tk documentation to include the solution you found, in case someone else without a closeable root window wants to use Twisted with Tkinter. Could you file a ticket for this? Jean-Paul
In article <20090413211444.24697.1739128157.divmod.quotient.7085@henry.divmod.com>, Jean-Paul Calderone <exarkun@divmod.com> wrote:
... It sounds like we should expand the Tk documentation to include the solution you found, in case someone else without a closeable root window wants to use Twisted with Tkinter. Could you file a ticket for this?
Great idea. Here it is: <http://twistedmatrix.com/trac/ticket/3776>. -- Russell
participants (2)
-
Jean-Paul Calderone
-
Russell E. Owen