从 PyInstaller 打包的 wxPython GUI 应用程序打开默认浏览器
Open default browser from wxPython GUI app packed by PyInstaller
我有 Python 3.7.5 应用程序,wxPython Phoenix GUI 由 PyInstaller 3.6 打包到 .exe。冻结是用这样的参数:
venv\Scripts\pyinstaller app.pyw --clean --onefile --windowed --add-binary icon.ico;. --add-binary logo-iconic.ico;. --add-binary vendor.exe;. --icon logo-iconic.ico --version-file file_version_info.txt
我正在尝试在应用 window 中点击按钮打开 link(例如,https://google.com)而不显示控制台 window。
我尝试了什么:
wx.LaunchDefaultBrowser('https://google.com')
subprocess.Popen('C:\Windows\explorer.exe https://google.com')
- Recipe 来自 PyInstaller wiki
如果我从 PyInstaller 参数中删除 --windowed
,应用程序会按预期运行 wx.LaunchDefaultBrowser('https://google.com')
,但控制台 window 会在应用程序启动时显示。如果像 PyInstaller 配方中那样将 stdout 和 stderr 重定向到文件,我什么也看不到,文件未创建。
如何在 PyInstaller 中打开默认 OS 浏览器 packed Python 带有 wxPython GUI 的应用程序而不显示控制台?
您可以使用 webbrowser
模块,stdlib 的一部分:
from webbrowser import open
open('http://google.com')
这将在用户默认浏览器中打开 google.com
。
我有 Python 3.7.5 应用程序,wxPython Phoenix GUI 由 PyInstaller 3.6 打包到 .exe。冻结是用这样的参数:
venv\Scripts\pyinstaller app.pyw --clean --onefile --windowed --add-binary icon.ico;. --add-binary logo-iconic.ico;. --add-binary vendor.exe;. --icon logo-iconic.ico --version-file file_version_info.txt
我正在尝试在应用 window 中点击按钮打开 link(例如,https://google.com)而不显示控制台 window。
我尝试了什么:
wx.LaunchDefaultBrowser('https://google.com')
subprocess.Popen('C:\Windows\explorer.exe https://google.com')
- Recipe 来自 PyInstaller wiki
如果我从 PyInstaller 参数中删除 --windowed
,应用程序会按预期运行 wx.LaunchDefaultBrowser('https://google.com')
,但控制台 window 会在应用程序启动时显示。如果像 PyInstaller 配方中那样将 stdout 和 stderr 重定向到文件,我什么也看不到,文件未创建。
如何在 PyInstaller 中打开默认 OS 浏览器 packed Python 带有 wxPython GUI 的应用程序而不显示控制台?
您可以使用 webbrowser
模块,stdlib 的一部分:
from webbrowser import open
open('http://google.com')
这将在用户默认浏览器中打开 google.com
。