[英]NSException in kivy with matplotlib and tkinter
我繼承了一些使用kivy / tkinter / matplotlib的代碼,這些代碼在Windows上可以正常運行,但在osx上存在一些問題。 一個問題已經在另一個問題中解決了。 運行以下NSException
時出現NSException
:
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(),然后說一切正常。當代碼繼續執行時,異常不會發生,並且一切運行正常。
所以我的問題是,這些NSExceptions的根源和本質通常是什么,tkinter._test()會做什么導致它不發生?
以及如何在沒有不必要的初始測試彈出窗口的情況下復制它的工作?
引發的異常是:
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()創建了一個根窗口,而盛大的解決方案就是在導入后創建一個根窗口:
import tkinter
root = tkinter.Tk()
root.withdraw()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.