| 1234567891011121314151617181920212223242526272829 |
- import objc
- from AppKit import NSApplication, NSWindow, NSTextField, NSApp, NSMakeRect, NSObject
- class AppDelegate(NSObject):
- def applicationDidFinishLaunching_(self, notification):
- window = NSWindow.alloc().initWithContentRect_styleMask_backing_defer_(
- NSMakeRect(0, 0, 400, 200),
- NSWindow.StyleMask.titled | NSWindow.StyleMask.closable | NSWindow.StyleMask.resizable,
- NSBackingStore.Buffered,
- False
- )
- window.center()
- window.setTitle_("Hello World App")
- window.makeKeyAndOrderFront_(None)
- label = NSTextField.alloc().initWithFrame_(NSMakeRect(0, 0, 400, 200))
- label.setStringValue_("Hello World")
- label.sizeToFit()
- label.setFrameOrigin_(NSMakePoint(0, 0))
- window.contentView().addSubview(label)
- def applicationShouldTerminateAfterLastWindowClosed_(self, sender):
- return True
- if __name__ == '__main__':
- NSApplication = NSApplication.sharedApplication()
- delegate = AppDelegate.alloc().init()
- NSApplication.setDelegate_(delegate)
- NSApplication.run()
|