Reputation: 627
I have written a Python script which uses Pyglet for the main window and Tkinter for an initial GUI window. This script works as expected on Windows, i.e. it shows the Tkinter GUI window and the Pyglet animation. However, it does not run properly on a Mac, I am not able to make both windows work together, they do work separately.
I have found that the error arises when the line master = Tk()
is executed, if the following libraries has been imported
from pyglet.gl import *
from pyglet.window import Window, mouse, key
The complete code I am using for testing this is:
import pyglet
from pyglet.gl import *
from pyglet.window import Window, mouse, key
from Tkinter import * # for the subject data gui
master = Tk()
And the error message I get from it is the following:
Python[1359:60f] -[NSApplication _setup:]: unrecognized selector sent to instance 0x10300adb0
Python[1359:60f] An uncaught exception was raised
ython[1359:60f] -[NSApplication _setup:]: unrecognized selector sent to instance 0x10300adb0
Python[1359:60f] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSApplication _setup:]: unrecognized selector sent to instance 0x10300adb0'
*** Call stack at first throw:
(
0 CoreFoundation 0x00007fff8685b7b4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x00007fff84e2c0f3 objc_exception_throw + 45
2 CoreFoundation 0x00007fff868b5110 +[NSObject(NSObject) doesNotRecognizeSelector:] + 0
3 CoreFoundation 0x00007fff8682d91f ___forwarding___ + 751
4 CoreFoundation 0x00007fff86829a68 _CF_forwarding_prep_0 + 232
5 Tk 0x0000000116cc2b24 TkpInit + 545
6 Tk 0x0000000116c389ee Initialize + 1648
7 _tkinter.so 0x0000000116af6c0d Tcl_AppInit + 77
8 _tkinter.so 0x0000000116af5657 Tkinter_Create + 919
9 Python 0x00000001000c2fad PyEval_EvalFrameEx + 21405
10 Python 0x00000001000c4fb3 PyEval_EvalCodeEx + 2115
11 Python 0x000000010003eac0 function_call + 176
12 Python 0x000000010000ceb2 PyObject_Call + 98
13 Python 0x000000010001f56d instancemethod_call + 365
14 Python 0x000000010000ceb2 PyObject_Call + 98
15 Python 0x00000001000bc957 PyEval_CallObjectWithKeywords + 87
16 Python 0x000000010002285e PyInstance_New + 126
17 Python 0x000000010000ceb2 PyObject_Call + 98
18 Python 0x00000001000c0c60 PyEval_EvalFrameEx + 12368
19 Python 0x00000001000c4fb3 PyEval_EvalCodeEx + 2115
20 Python 0x00000001000c50d6 PyEval_EvalCode + 54
21 Python 0x00000001000e995e PyRun_FileExFlags + 174
22 Python 0x00000001000e9bfa PyRun_SimpleFileExFlags + 458
23 Python 0x0000000100100c0d Py_Main + 3101
24 Python 0x0000000100000f14 0x0 + 4294971156
25 ??? 0x0000000000000002 0x0 + 2
)
terminate called after throwing an instance of 'NSException'
Abort trap
I do not understand what this error means, can anyone help me understand what have I done wrong?
Upvotes: 2
Views: 1279
Reputation: 739
I know this is an old question, but I get asked this by my grad student all the time. Especially when they are copying code from the web.
You're almost certainly having a namespace clash.
You are doing an import *
or importing names such as Window, mouse, key
from pyglet and then doing an import *
from tkinter. When using 2 graphics libraries at once, it a good idea to either deal either deal with the full namespace, e.g., referring to things like pyglet.window.Window
or alias things, e.g., import pyglet.window as pw
and then using pw.Window
or pw.mouse
.
The code you posted generates the same exception for me, but this version completes without an error:
# import pyglet
# from pyglet.gl import *
# from pyglet.window import Window, mouse, key
import tkinter # import * # for the subject data gui
master = tkinter.Tk()
Note: I used lowercase tkinter
because I'm using Python 3.6
Upvotes: 2