On Apr 7, 2009, at 1:08 PM, Kevin Walzer wrote:

Russell E. Owen wrote:
Anyone know how to redefine what the File>Quit menu item does on MacOS X using Aqua Tcl/Tk? I am trying to convert a cross-platform application to use Twisted, and unfortunately this seems to make the pre-existing Quit menu item on MacOS X do *nothing*. I can't quit the application without using ctrl-C or closing the root window (not an option for this application). I have tried to configure that menu item, but tk does not seem to know that it exists (the index of the last menu item is too small).
Any suggestions would be most welcome.
-- Russell

The pre-defined "Quit" menu entry that comes with Tk/Aqua is in the application menu, not the file menu. In my two Python/Tk apps, hitting "Command-Q" quits them without any code on my part--Tk is invoking the standard "quit" event.

That is the one I meant (as you surmised).

The normal Quit menu item has always worked fine for me until I switched to using Twisted framework. Now it does nothing.

If...you are talking about the "Quit" entry in the app menu, try something like this:

self.bind('Command-Key-Q', lamdba event: sys.exit())


What should self be to bind this application-wide (for all windows and widgets)? Root doesn't seem to accept key events.

(Also, although this is much better than nothing, presumably it will not actually support the Quit menu item? If so, I hope to find a more thorough solution.)

-- Russell

P.S. here is a minimal Twisted/Tkinter application that cannot be quit normally:
import Tkinter
import twisted.internet.tksupport
root = Tkinter.Tk()
twisted.internet.tksupport.install(root)
reactor = twisted.internet.reactor
reactor.run()


Whereas the following minimal non-Twisted application quits normally:
import Tkinter
root = Tkinter.Tk()
root.mainloop()

_______________________________________________
Tkinter-discuss mailing list
Tkinter-discuss@python.org
http://mail.python.org/mailman/listinfo/tkinter-discuss

Reply via email to