使用 PyObjC 以 NSWindow 的风格初始化 NSPanel

问题描述

我从 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 手动打开窗口。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)