问题
The following simple code:
from PyObjCTools import AppHelper
import AppKit
import Tkinter
class App(AppKit.NSApplication):
def finishLaunching(self):
self.root=Tkinter.Tk()
_=App.sharedApplication()
AppHelper.runEventLoop()
yields the following exception: Python[23717:d07] -[App _setup:]: unrecognized selector sent to instance 0x105d05340
What am I doing wrong?
回答1:
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).
My recommendation would be to use one UI toolkit or the other, but not both.
来源:https://stackoverflow.com/questions/7042500/integration-issue-with-pyobjc-and-tkinter