On Jun 29, 2011, at 11:23 PM, Thomas Cool wrote:

Hello,
I'm starting with PyObjC and am having some trouble creating windows
I am not a beginner at either python or cocoa by the way.

Here is what i am trying (both with macports python 2.6 and builtin python 2.6) on 10.6.8

from AppKit import *
a=NSWindow.alloc().init()

simply this returns an error:

Wed Jun 29 16:23:09 TCi7.local python[10060] <Error>: kCGErrorInvalidConnection: CGSGetCurrentCursorLocation: Invalid connection
Wed Jun 29 16:23:09 TCi7.local python[10060] <Error>: kCGErrorInvalidConnection: CGSNewWindowWithOpaqueShape: Invalid connection
Traceback (most recent call last):
 File "<stdin>", line 1, in <module>
objc.error: NSInternalInconsistencyException - Error (1002) creating CGSWindow


Let me guess, you just wrote that into a script, and executed it?

It won't work in Objective-C either, if all you do is just to create a simple executable.

Instead, you need to create an application bundle, using py2app. Otherwise, the window-server refuses to accept connections. I never really bothered to get to know the gory details, but see e.g. this discussion:

 http://stackoverflow.com/questions/3704629/why-cant-i-use-cocoa-classes-from-my-python-script

And especially the related tech-note.

Diez