Web Analytics Made Easy - Statcounter
Skip to content

Recipe- Launch a Program With a Button

Very simple script that will launch a program as a subprocess. Great for making a desktop launcher toolbar. In version 4.35.0 of PySimpleGUI the Exec APIs were added. These enable you to launch subprocesses

import PySimpleGUI as sg

CHROME = r"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"


layout = [  [sg.Text('Text area', key='-TEXT-')],
            [sg.Input(key='-URL-')],
            [sg.Button('Chrome'), sg.Button('Exit')]]

window = sg.Window('Window Title', layout)

while True:             # Event Loop
    event, values = window.read()
    print(event, values)
    if event == sg.WIN_CLOSED or event == 'Exit':
        break
    if event == 'Chrome':
        sg.execute_command_subprocess(CHROME)

window.close()