Search code examples
pythonwxpythonpyinstaller

Open default browser from wxPython GUI app packed by PyInstaller


I have Python 3.7.5 app with wxPython Phoenix GUI packed to .exe by PyInstaller 3.6. Freezing was with such params:

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

I'm trying to open link (for example, https://google.com) on button click in app window without showing console window.

What I tried:

  • wx.LaunchDefaultBrowser('https://google.com')
  • subprocess.Popen('C:\\Windows\\explorer.exe https://google.com')
  • Recipe from PyInstaller wiki

If I delete --windowed from PyInstaller params, app worked as expected with wx.LaunchDefaultBrowser('https://google.com'), but console window shows on app start. If redirect stdout and stderr to file as in PyInstaller recipe, I see nothing, file not created.

How to open default OS browser in PyInstaller packed Python app with wxPython GUI without console appearing?


Solution

  • You can use the webbrowser module, part of the stdlib:

    from webbrowser import open
    open('http://google.com')
    

    This will open google.com in the users default browser.