Vincent
Vincent

Reputation: 556

NSException in kivy with matplotlib and tkinter

I have inherited some code thats using kivy/tkinter/matplotlib which run fine on windows but has some problems on osx. One problem was solved already in another question. I'm getting an NSException when I run the following:

import tkinter
# tkinter._test()

import matplotlib
matplotlib.use("TkAgg")
from matplotlib import pyplot as plt
import kivy.core.window

from tkinter.filedialog import askopenfilename

askopenfilename(initialdir='/', title="Open files")

I don't get the exception unless I call askopenfilename. Now I was thinking "maybe tkinter isn't working" so I threw in the initial tkinter._test(), which then says everything is ok... and when the code afterwards continues the exception doesn't occur and everything runs just fine.

So my question is, what is typically the root and nature of these NSExceptions, and what could tkinter._test() be doing that causes it not to occur?

And how to I replicate what it's doing without having the unwanted initial test popup?

The thrown exception is:

2017-03-08 15:16:00.199 Python[31489:260345] -[SDLApplication _setup:]: unrecognized selector sent to instance 0x1021727f0
2017-03-08 15:16:00.203 Python[31489:260345] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[SDLApplication _setup:]: unrecognized selector sent to instance 0x1021727f0'
*** First throw call stack:
(
    0   CoreFoundation                      0x00007fffa8716e7b __exceptionPreprocess + 171
    1   libobjc.A.dylib                     0x00007fffbd300cad objc_exception_throw + 48
    ...
    53  Python                              0x0000000100000c34 Python + 3124
)
libc++abi.dylib: terminating with uncaught exception of type NSException

Upvotes: 1

Views: 858

Answers (1)

Vincent
Vincent

Reputation: 556

So I feel silly, the reason was simply that _test() creates a root window, and the grand solution is just to create a root window after importing:

import tkinter
root = tkinter.Tk()
root.withdraw()

Upvotes: 2

Related Questions