0

我从 PyObjC 文档中下载了一个示例代码,并将其删除了大部分非必要内容。然后我将 NSWindow 的所有引用更改为 NSPanel,但这没有任何效果。

from Cocoa import NSObject, NSApplication, NSApp, NSWindow, NSButton, NSSound, NSPanel
from PyObjCTools import AppHelper

def main():
    NSApplication.sharedApplication()

    # we must keep a reference to the delegate object ourselves,
    # NSApp.setDelegate_() doesn't retain it. A local variable is
    # enough here.
    delegate = NSPanel.alloc().init()
    NSApp().setDelegate_(delegate)

    win = NSPanel.alloc()
    frame = ((200.0, 700.0), (100.0, 100.0))
    win.initWithContentRect_styleMask_backing_defer_(frame, 15, 2, 0)
    win.setLevel_(3)  # floating window
    win.display()
    win.orderFrontRegardless()  # but this one does

    AppHelper.runEventLoop()

if __name__ == "__main__":
    main()

我不能让这个窗口成为一个 HUD NSPanel,它保持在一个普通的 NSWindow 的形式。其次,它似乎win.orderFrongRegardless()不能正常工作,因为我必须在运行代码后从我的 Dock 手动打开窗口。

4

0 回答 0