开发者

Integration issue with PyObjC and TKinter

开发者 https://www.devze.com 2023-03-28 05:53 出处:网络
The following simple code: from PyObjCTools import 开发者_如何学GoAppHelper import AppKit import Tkinter

The following simple code:

from PyObjCTools import 开发者_如何学GoAppHelper
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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消