我正在尝试为我正在处理的应用程序构建一个GUI,但是当我尝试调整窗口大小时,我遇到了一个奇怪的崩溃。
似乎python它的自我崩溃但我无法追查问题。任何帮助表示赞赏。
2018-01-26 17:20:29.424 Python[7025:727130] *** Terminating app due to uncaught exception 'CALayerInvalidGeometry', reason: 'CALayer position contains NaN: [0 nan]'
*** First throw call stack:
(
0 CoreFoundation 0x00007fff9f95152b __exceptionPreprocess + 171
1 libobjc.A.dylib 0x00007fffb4027cad objc_exception_throw + 48
2 CoreFoundation 0x00007fff9f9cfa0d +[NSException raise:format:] + 205
3 QuartzCore 0x00007fffa54f7980 _ZN2CA5Layer12set_positionERKNS_4Vec2IdEEb + 152
4 QuartzCore 0x00007fffa54f7af5 -[CALayer setPosition:] + 44
5 QuartzCore 0x00007fffa54f814b -[CALayer setFrame:] + 644
6 CoreUI 0x00007fffab2a1112 _ZN20CUICoreThemeRenderer26MakeOrUpdateScrollBarLayerEPK13CUIDescriptoraPP7CALayer + 1284
7 CoreUI 0x00007fffab29d317 _ZN20CUICoreThemeRenderer19CreateOrUpdateLayerEPK13CUIDescriptorPP7CALayer + 1755
8 CoreUI 0x00007fffab21f4d1 _ZN11CUIRenderer19CreateOrUpdateLayerEPK14__CFDictionaryPP7CALayer + 175
9 CoreUI 0x00007fffab222185 CUICreateOrUpdateLayer + 221
10 AppKit 0x00007fff9df86623 -[NSCompositeAppearance _callCoreUIWithBlock:options:] + 226
11 AppKit 0x00007fff9d633a9d -[NSAppearance _createOrUpdateLayer:options:] + 76
12 AppKit 0x00007fff9d8ac143 -[NSScrollerImp _animateToRolloverState] + 274
13 AppKit 0x00007fff9d86bb79 __49-[NSScrollerImp _installDelayedRolloverAnimation]_block_invoke + 673
14 AppKit 0x00007fff9d732331 -[NSScrollerImp _doWork:] + 15
15 Foundation 0x00007fffa132fc88 __NSFireDelayedPerform + 417
16 CoreFoundation 0x00007fff9f8d0e14 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 20
17 CoreFoundation 0x00007fff9f8d0a9f __CFRunLoopDoTimer + 1071
18 CoreFoundation 0x00007fff9f8d05fa __CFRunLoopDoTimers + 298
19 CoreFoundation 0x00007fff9f8c8021 __CFRunLoopRun + 2065
20 CoreFoundation 0x00007fff9f8c75b4 CFRunLoopRunSpecific + 420
21 Tcl 0x0000000108db4b43 Tcl_WaitForEvent + 314
22 Tcl 0x0000000108d845cd Tcl_DoOneEvent + 274
23 _tkinter.cpython-36m-darwin.so 0x0000000108cfd760 _tkinter_tkapp_mainloop + 252
24 Python 0x0000000108703641 _PyCFunction_FastCallDict + 166
25 Python 0x0000000108767cde call_function + 489
26 Python 0x0000000108760b93 _PyEval_EvalFrameDefault + 4811
27 Python 0x0000000108768440 _PyEval_EvalCodeWithName + 1719
28 Python 0x0000000108768b43 fast_function + 218
29 Python 0x0000000108767cb5 call_function + 448
30 Python 0x0000000108760b93 _PyEval_EvalFrameDefault + 4811
31 Python 0x0000000108768440 _PyEval_EvalCodeWithName + 1719
32 Python 0x000000010875f84e PyEval_EvalCode + 42
33 Python 0x000000010878819e run_mod + 54
34 Python 0x00000001087871bf PyRun_FileExFlags + 160
35 Python 0x000000010878689c PyRun_SimpleFileExFlags + 285
36 Python 0x000000010879a6c0 Py_Main + 3484
37 Python 0x00000001086bee1d Python + 7709
38 libdyld.dylib 0x00007fffb4905255 start + 1
39 ??? 0x0000000000000002 0x0 + 2
)
libc++abi.dylib: terminating with uncaught exception of type NSException
Abort trap: 6
以下是相关的python文件:
try:
import tkinter as tk
from tkinter.scrolledtext import ScrolledText
from tkspellcheck import TextEventMixin, Spellcheck
except ImportError:
import Tkinter as tk
from tkspellcheck import TextEventMixin, Spellcheck
from ScrolledText import ScrolledText
class App(tk.Tk):
def __init__(self):
tk.Tk.__init__(self)
## Toolbar
self.toolbar = tk.Frame()
self.toolbar.pack(side="top", fill="x")
self.status = tk.Label(self.toolbar, width=15, relief=tk.SUNKEN)
self.status.pack(side=tk.RIGHT, fill=tk.X, expand=1)
self.text = ExampleText(self, width=80, wrap=tk.WORD, highlightthickness=0) # I Think the problem relates to these two lines
self.text.pack(side=tk.BOTTOM, fill=tk.BOTH, expand=1) #I Think the problem relates to these two lines
## From example at https://github.com/bencorman/tkspellcheck
def update_wordcount(self):
wc = len(self.text.get('1.0', 'end').split(' '))
wcount = 'Wordcount: {0}'.format(wc)
self.status.config(text=wcount)
## From example at https://github.com/bencorman/tkspellcheck
class ExampleText(TextEventMixin, ScrolledText):
"""Adapted from: http://code.activestate.com/recipes/464635
"""
def __init__(self, root, *args, **kw):
ScrolledText.__init__(self, root, *args, **kw)
self.root = root
self.spellcheck = Spellcheck(self)
self.spellcheck.spellcheck_enabled = True
self._init_textevent_mixin()
def fire_on_textevent(self):
self.root.update_wordcount()
self.spellcheck.run()
if __name__ == "__main__":
app=App()
app.mainloop()
## File From https://github.com/bencorman/tkspellcheck
import tk
#from enchant.checker import SpellChecker
#from enchant.tokenize import EmailFilter, URLFilter, HTMLChunker
class TextEventMixin(object):
"""Adds a trigger to the Tkinter Text widget that fires on modification.
From: http://code.activestate.com/recipes/464635
"""
def _init_textevent_mixin(self):
"""Call this from the text widget to bind the <<Modified>> event to the
Callback.
"""
# Clear the alert flag and set up the _reset_alert_flag attribute.
self._reset_alert_flag()
# Bind the <<Modified>> virtual event to the internal callback.
self.bind('<<Modified>>', self._txtevt)
def _txtevt(self, evt):
"""Calls the user callback and resets the <<Modified>> event.
"""
# If this is being called recursively as a result of the call to
# _reset_alert_flag() below, then we do nothing.
if not self._resetting_alert_flag:
# Clear the Tk 'modified' variable.
self._reset_alert_flag()
# Call the user-defined callback.
self.fire_on_textevent()
def fire_on_textevent(self):
"""Override this method in your class. This is called whenever the
<<Modified>> event is triggered.
"""
pass
def _reset_alert_flag(self):
"""Reset the <<Modified>> event to false so it'll fire again on the next
modification.
Setting the Text Widget's modified variable triggers the <<Modified>>
event which can trigger _txtevt() recursively.
This uses the _resetting_alert_flag to disable the internal callback
_txtevt() to avoid this recursive call.
"""
# Set the flag, disable the internal callback
self._resetting_alert_flag = True
# edit_modified() only recently became a valid call?
# The Tkinter Text modified variable can also be set via:
# self.tk.call(self._w, 'edit', 'modified', 0)
# edit_modified() information here:
# http://epydoc.sourceforge.net/stdlib/Tkinter.Text-class.html#edit_modified
self.edit_modified(False)
# Unset the flag, enable the internal callback
self._resetting_alert_flag = False
class Spellcheck(object):
def __init__(self, textwidget, **kw):
pass
答案 0 :(得分:1)
我已经解决了我的问题。
如果其他人遇到类似的问题,请参阅如何修复它的快速教程。这对我在MacOS 10.12上的作用
我在python.org上找到了这个页面,它几乎总结了我遇到的问题。在一行中它说:“不要使用预先安装的tkinter版本”。