使用Python和Tkinter来创build一个简单的GUI,我得到无法识别的select器发送到实例

我正在学习如何使用Python制作GUI程序。 我正在使用Python 2.7.6。 这里是一个带有标签的简单窗口的代码:

from Tkinter import * root = Tk() label = Label(root, text="hello") label.pack() root.mainloop() 

此代码适用于我的Windows 7计算机,但不适用于我的Mac OSX 10.10.4。 在Mac上,我得到以下错误:

  2015-08-18 10:32:09.137 Python[11678:5520486] -[QNSApplication_setup:]: unrecognized selector sent to instance 0x10f83bd10 2015-08-18 10:32:09.137 Python[11678:5520486] -[QNSApplication _setup:]: unrecognized selector sent to instance 0x10f83bd10 2015-08-18 10:32:09.139 Python[11678:5520486] ( 0 CoreFoundation 0x00007fff8ccc303c __exceptionPreprocess + 172 1 libobjc.A.dylib 0x00007fff8ee8a76e objc_exception_throw + 43 2 CoreFoundation 0x00007fff8ccc60ad -[NSObject(NSObject) doesNotRecognizeSelector:] + 205 3 CoreFoundation 0x00007fff8cc0be24 ___forwarding___ + 1028 4 CoreFoundation 0x00007fff8cc0b998 _CF_forwarding_prep_0 + 120 5 Tk 0x00000001199b1527 TkpInit + 476 6 Tk 0x000000011992baca Tk_Init + 1788 7 _tkinter.so 0x0000000110b01ceb Tcl_AppInit + 75 8 _tkinter.so 0x0000000110afef14 Tkinter_Create + 916 9 Python 0x00000001000c6ced PyEval_EvalFrameEx + 25213 10 Python 0x00000001000c8fb9 PyEval_EvalCodeEx + 2137 11 Python 0x00000001000419e0 function_call + 176 12 Python 0x000000010000fe02 PyObject_Call + 98 13 Python 0x000000010002251b instancemethod_call + 363 14 Python 0x000000010000fe02 PyObject_Call + 98 15 Python 0x00000001000bf7b7 PyEval_CallObjectWithKeywords + 87 16 Python 0x000000010002580e PyInstance_New + 126 17 Python 0x000000010000fe02 PyObject_Call + 98 18 Python 0x00000001000c4138 PyEval_EvalFrameEx + 14024 19 Python 0x00000001000c8fb9 PyEval_EvalCodeEx + 2137 20 Python 0x00000001000c90d6 PyEval_EvalCode + 54 21 Python 0x00000001000edc2e PyRun_FileExFlags + 174 22 Python 0x00000001000bdb6c builtin_execfile + 364 23 Python 0x00000001000c7132 PyEval_EvalFrameEx + 26306 24 Python 0x00000001000c8fb9 PyEval_EvalCodeEx + 2137 25 Python 0x00000001000419e0 function_call + 176 26 Python 0x000000010000fe02 PyObject_Call + 98 27 Python 0x00000001000c1d2d PyEval_EvalFrameEx + 4797 28 Python 0x00000001000c8fb9 PyEval_EvalCodeEx + 2137 29 Python 0x00000001000419e0 function_call + 176 30 Python 0x000000010000fe02 PyObject_Call + 98 31 Python 0x00000001000c1d2d PyEval_EvalFrameEx + 4797 32 Python 0x00000001000c8fb9 PyEval_EvalCodeEx + 2137 33 Python 0x00000001000c68ad PyEval_EvalFrameEx + 24125 34 Python 0x00000001000c8fb9 PyEval_EvalCodeEx + 2137 35 Python 0x00000001000c68ad PyEval_EvalFrameEx + 24125 36 Python 0x00000001000c8fb9 PyEval_EvalCodeEx + 2137 37 Python 0x00000001000419e0 function_call + 176 38 Python 0x000000010000fe02 PyObject_Call + 98 39 Python 0x00000001000c1d2d PyEval_EvalFrameEx + 4797 40 Python 0x00000001000c8fb9 PyEval_EvalCodeEx + 2137 41 Python 0x00000001000c68ad PyEval_EvalFrameEx + 24125 42 Python 0x00000001000c8fb9 PyEval_EvalCodeEx + 2137 43 Python 0x00000001000419e0 function_call + 176 44 Python 0x000000010000fe02 PyObject_Call + 98 45 Python 0x00000001000c1d2d PyEval_EvalFrameEx + 4797 46 Python 0x00000001000c8fb9 PyEval_EvalCodeEx + 2137 47 Python 0x00000001000c68ad PyEval_EvalFrameEx + 24125 48 Python 0x00000001000c8fb9 PyEval_EvalCodeEx + 2137 49 Python 0x00000001000c68ad PyEval_EvalFrameEx + 24125 50 Python 0x00000001000c8fb9 PyEval_EvalCodeEx + 2137 51 Python 0x00000001000c85df PyEval_EvalFrameEx + 31599 52 Python 0x00000001000c8fb9 PyEval_EvalCodeEx + 2137 53 Python 0x00000001000c68ad PyEval_EvalFrameEx + 24125 54 Python 0x00000001000c8fb9 PyEval_EvalCodeEx + 2137 55 Python 0x00000001000c68ad PyEval_EvalFrameEx + 24125 56 Python 0x00000001000c8fb9 PyEval_EvalCodeEx + 2137 57 Python 0x00000001000c68ad PyEval_EvalFrameEx + 24125 58 Python 0x00000001000c8fb9 PyEval_EvalCodeEx + 2137 59 Python 0x00000001000c68ad PyEval_EvalFrameEx + 24125 60 Python 0x00000001000c8fb9 PyEval_EvalCodeEx + 2137 61 Python 0x00000001000c68ad PyEval_EvalFrameEx + 24125 62 Python 0x00000001000c8fb9 PyEval_EvalCodeEx + 2137 63 Python 0x00000001000419e0 function_call + 176 64 Python 0x000000010000fe02 PyObject_Call + 98 65 Python 0x00000001000c1d2d PyEval_EvalFrameEx + 4797 66 Python 0x00000001000c8fb9 PyEval_EvalCodeEx + 2137 67 Python 0x00000001000419e0 function_call + 176 68 Python 0x000000010000fe02 PyObject_Call + 98 69 Python 0x00000001000c1d2d PyEval_EvalFrameEx + 4797 70 Python 0x00000001000c8fb9 PyEval_EvalCodeEx + 2137 71 Python 0x00000001000c68ad PyEval_EvalFrameEx + 24125 72 Python 0x00000001000c8fb9 PyEval_EvalCodeEx + 2137 73 Python 0x00000001000c68ad PyEval_EvalFrameEx + 24125 74 Python 0x00000001000c8fb9 PyEval_EvalCodeEx + 2137 75 Python 0x00000001000c68ad PyEval_EvalFrameEx + 24125 76 Python 0x00000001000c8fb9 PyEval_EvalCodeEx + 2137 77 Python 0x00000001000c68ad PyEval_EvalFrameEx + 24125 78 Python 0x00000001000c8fb9 PyEval_EvalCodeEx + 2137 79 Python 0x00000001000419e0 function_call + 176 80 Python 0x000000010000fe02 PyObject_Call + 98 81 Python 0x00000001000bf7b7 PyEval_CallObjectWithKeywords + 87 82 libpyside-python2.7.1.2.2.dylib 0x0000000102c67faa _ZN6PySide13SignalManager20callPythonMetaMethodERK11QMetaMethodPPvP7_objectb + 122 ) 

任何帮助理解为什么它在Windows计算机,但不是Mac的作品,赞赏。

谢谢

你是从哪个脚本运行的? 闲? 在OSX上有一个TK和IDLE的已知问题。

https://www.python.org/download/mac/tcltk/

最新版本的Tcl / Tk需要安装,如果您使用IDLE,请尝试不同的环境。