Skip to content

[pywebview] Error while processing windows.native.AccessibilityObject.Bounds.Empty.Empty.Empty.Empty.......... #1815

@wbw123a

Description

@wbw123a

def main():
# 1. 创建 API 实例(将暴露给 JS)
api = Api()

# 2. 构建 HTML 文件的绝对路径
static_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), "static")
html_path = os.path.join(static_dir, "index.html")

# 3. 创建主窗口
main_window = webview.create_window(
    title="pywebview Demo - 主窗口",
    url=html_path,  # 加载外部 HTML 文件(file:// 协议)
    js_api=api,
    width=780,
    height=650,
    resizable=True,
)
api.set_windows(main_window)

这样就会报错[pywebview] Error while processing windows.native.AccessibilityObject.Bounds.Empty.Empty.Empty.Empty..........
应该api.set_windows(main_window)放到 main_window.events.loaded += lambda: on_loaded(api, main_window)
def main():
# 1. 创建 API 实例(将暴露给 JS)
api = Api()

# 2. 构建 HTML 文件的绝对路径
static_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), "static")
html_path = os.path.join(static_dir, "index.html")

# 3. 创建主窗口
main_window = webview.create_window(
    title="pywebview Demo - 主窗口",
    url=html_path,  # 加载外部 HTML 文件(file:// 协议)
    js_api=api,
    width=780,
    height=650,
    resizable=True,
)
# 4. 绑定窗口事件
main_window.events.loaded += lambda: on_loaded(api, main_window)

def on_loaded(api,windows):
"""窗口加载完成时触发"""
print("[事件] 窗口正在开启...")
api.set_windows(windows)
虽然也不会有什么影响,但是我尝试出来,所以想分享出来

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions