Integration issue with PyObjC and TKinter

风流意气都作罢 提交于 2019-12-25 03:48:08

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!