带有matplotlib和tkinter的Kivy中的NSException [英] NSException in kivy with matplotlib and tkinter
问题描述
我继承了一些使用kivy/tkinter/matplotlib的代码,这些代码在Windows上可以正常运行,但在osx上存在一些问题.一个问题已经另一个问题已解决 .运行以下命令时得到NSException
:
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")
除非我打电话给askopenfilename,否则我不会得到例外. 现在我在想也许tkinter无法正常工作",所以我放入了最初的tkinter._test(),然后它说一切正常……而当代码继续执行时,则不会发生异常,并且一切正常.
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.
所以我的问题是,这些NSExceptions的根源和本质通常是什么,tkinter._test()会做什么而导致它不发生?
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?
抛出的异常是:
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
推荐答案
所以我觉得很愚蠢,原因仅仅是_test()创建了一个根窗口,而解决方案只是在导入后创建一个根窗口:
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()
这篇关于带有matplotlib和tkinter的Kivy中的NSException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!