PyObjC和TKinter的集成问题 [英] Integration issue with PyObjC and TKinter
问题描述
以下简单代码:
from PyObjCTools import AppHelper
import AppKit
import Tkinter
class App(AppKit.NSApplication):
def finishLaunching(self):
self.root=Tkinter.Tk()
_=App.sharedApplication()
AppHelper.runEventLoop()
产生以下异常:Python[23717:d07] -[App _setup:]: unrecognized selector sent to instance 0x105d05340
我在做什么错了?
推荐答案
我不认为您可以如此交替地混合使用Tkinter和Cocoa工具包. self.root
是类App
的属性,该类继承自AppKit.NSApplication
.我的猜测是Tk()
调用返回一个指针,该指针随后传递给Cocoa框架,但指向它无法理解的Tk数据结构.同样,Tkinter和PyObjC都需要自己的事件循环.我不确定您是否可以将两者混合使用(尽管我从未尝试过).
I don't think you can mix Tkinter and Cocoa toolkits so interchangeably. self.root
is an attribute on the class App
, which inherits from AppKit.NSApplication
. My guess is that the Tk()
call returns a pointer that is then passed to the Cocoa frameworks, but points to a Tk data structure that it can't understand. Also, both Tkinter and PyObjC need their own eventloop; I'm not sure if you can even mix the two (though I've never tried).
我的建议是使用一个或两个UI工具包,但不要同时使用两者.
My recommendation would be to use one UI toolkit or the other, but not both.
这篇关于PyObjC和TKinter的集成问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!