本次提交完成了整体项目的目录梳理与代码迁移: 1. 将根级controlplane、webhost等目录的代码迁移至desktop/对应子目录,统一桌面端架构 2. 移动并整理了插件目录结构,将插件统一放入根级plugins/ 3. 调整了前端项目的路径与配置,统一前后端开发构建流程 4. 清理了废弃的旧版app/目录与冗余的构建中间文件 5. 更新了.gitignore与README.md,适配新的项目结构
80 lines
3.0 KiB
Markdown
80 lines
3.0 KiB
Markdown
保持系统原生标题栏
|
||
这是让标题栏看起来像正常桌面软件的第一步。
|
||
|
||
在 webview.create_window() 中,不要设置 frameless=True。保持默认值 frameless=False,pywebview 就会使用 Windows 系统原生的标题栏和最小化/最大化/关闭按钮。
|
||
|
||
python
|
||
window = webview.create_window(
|
||
title='我的应用',
|
||
url='...',
|
||
frameless=False, # 关键:使用系统原生标题栏
|
||
easy_drag=False # 原生标题栏无需 easy_drag
|
||
)
|
||
📄 嵌入正确的 Manifest
|
||
这是解决标题栏样式“不对劲”最关键的一步。创建 app.manifest 文件,声明启用 Common Controls 6.0 和 DPI 感知。
|
||
|
||
xml
|
||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
|
||
<assemblyIdentity version="1.0.0.0" processorArchitecture="*"
|
||
name="MyCompany.MyApp" type="win32"/>
|
||
<description>MyApp</description>
|
||
<dependency>
|
||
<dependentAssembly>
|
||
<assemblyIdentity type="win32"
|
||
name="Microsoft.Windows.Common-Controls"
|
||
version="6.0.0.0"
|
||
processorArchitecture="*"
|
||
publicKeyToken="6595b64144ccf1df"
|
||
language="*"/>
|
||
</dependentAssembly>
|
||
</dependency>
|
||
<application xmlns="urn:schemas-microsoft-com:asm.v3">
|
||
<windowsSettings>
|
||
<dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true/pm</dpiAware>
|
||
<dpiAwareness xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">PerMonitorV2, PerMonitor</dpiAwareness>
|
||
</windowsSettings>
|
||
</application>
|
||
</assembly>
|
||
打包时通过 --manifest 参数嵌入:
|
||
|
||
bash
|
||
pyinstaller --noconfirm --clean --windowed --name MyApp ^
|
||
--icon app.ico ^
|
||
--manifest app.manifest ^
|
||
main.py
|
||
🖼️ 设置窗口图标
|
||
--icon app.ico 只改变 exe 文件本身的图标。运行时窗口标题栏左上角的图标,不会自动跟着变,默认还是 Python 的图标。
|
||
|
||
对于 Windows,pywebview 官方推荐的方式是通过打包工具嵌入图标,而不是用 webview.start(icon=...)。所以 --icon app.ico 配合 PyInstaller 打包,是 Windows 下的正确做法。有 PR 已经为 WinForms 后端添加了 webview.start(icon=...) 的支持,但最稳妥的方式仍然是打包时嵌入。
|
||
|
||
📌 设置 AppUserModelID
|
||
这一步解决任务栏图标分组和固定的问题。在程序入口最前面调用:
|
||
|
||
python
|
||
import ctypes
|
||
try:
|
||
ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID("MyCompany.MyApp")
|
||
except Exception:
|
||
pass
|
||
字符串可以自定义,但如果你做了安装包和快捷方式,快捷方式的 AppUserModelID 也要保持一致。
|
||
|
||
📦 完整入口代码示例
|
||
python
|
||
import ctypes
|
||
import webview
|
||
|
||
try:
|
||
ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID("MyCompany.MyApp")
|
||
except Exception:
|
||
pass
|
||
|
||
if __name__ == "__main__":
|
||
window = webview.create_window(
|
||
title="我的应用",
|
||
url="http://127.0.0.1:8000", # 或 file:// 加载 Vue dist
|
||
width=1200,
|
||
height=800,
|
||
frameless=False
|
||
)
|
||
webview.start(debug=False) |