[issue46573] Python modules such as pyglet or pygame crash Python when tkinter message boxes are opened on MacOS.

Ronald Oussoren report at bugs.python.org
Wed Feb 2 05:11:45 EST 2022


Ronald Oussoren <ronaldoussoren at mac.com> added the comment:

I've done some more research and this is an integration issue between pyglet and Tk. In particular:

* Both pyglet and Tk use AppKit to implement their GUI
* AppKit uses an NSApplication class, and in particular a singleton instance of that class, to represent the application, which will get instantiated during application startup
* The Tk library uses a sublclass of NSApplication with additional functionality (TkApplication).
* When pyglet is started first the NSApplication singleton is an instance of NSApplication and not of TkApplication, but Tk's implementation assumes that the singleton is an instance of TkApplicationo.

A workaround for this issue is to make sure Tk is initialised before initialising pyglet. For example using this code at the start of the script: "from tkinter import Tk; root = Tk()"


There's not much we can do about this in CPython, other than maybe filing an issue with the Tk project about this. I haven't looked at the Tk codebase and there cannot tell how hard it would be for then to avoid a dependency on TkApplication as a separate class (for example by implementing the additional functionality they need in a category on NSApplication).

----------
resolution:  -> third party
stage:  -> resolved
status: open -> pending

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue46573>
_______________________________________


More information about the Python-bugs-list mailing list