I'm pretty new to Python and have been working with PySimpleGUI. I have created a simple program in Windows 11 that opens Google when you press a button on the GUI. It works fine if Chrome is already open, but it crashes after pressing the "Go" button if Chrome isn't already open. I'm using Python 3.11.4 and PySimpleGUI 4.60.5.
Here is the code that I have:
import PySimpleGUI as sg
import os
layout = [
[sg.Text('Press "Open Google" to open Google.')],
[sg.Button("Exit"), sg.Button("Open Google", key = "-GOOGLE-")]
]
window = sg.Window("Test Window", layout)
b=0
while True:
b+=1
event, values = window.Read()
if event in ("Exit", sg.WIN_CLOSED):
window.Close()
break
if event == "-GOOGLE-":
os.system("\"C:\Program Files\Google\Chrome\Application\chrome.exe\" -incognito https://google.com")
I don't want to use Chrome web driver, I'm trying to open a normal Chrome window.
The problem is laid out a lot better here: Opening Chrome From Command Line.
The problem was with the command itself. For some reason, opening chrome.exe without a chrome tab open causes the prompt to hang, and not be able to fully execute. Using start chrome -incognito "site1.com"
works fine. In python, this would look like:
os.system("start chrome -incognito https://google.com")