固定版本Webview2可以到 https://developer.microsoft.com/zh-cn/microsoft-edge/webview2 下载,本解决方案参考自 https://learn.microsoft.com/zh-cn/microsoft-edge/webview2/concepts/distribution?tabs=dotnetcsharp#details-about-the-fixed-version-runtime-distribution-mode 。
代码如下:
from nicegui import ui
import os
import pathlib
os.environ['WEBVIEW2_BROWSER_EXECUTABLE_FOLDER'] = str(pathlib.Path(__file__).parent/'Microsoft.WebView2.FixedVersionRuntime.135.0.3179.98.x64')
ui.run(native=True)
这里是将固定版本Webview2解压之后,将包含可执行文件msedgewebview2.exe的文件夹放到源代码的同级目录中,读者在实际使用时可以自行变换路径。