Web Analytics Made Easy - Statcounter
Skip to content

Desktop Floating Toolbar

Hiding your windows commmand window

If you would like your python program to run without showing a console window, then you can name your file with a .pyw extension and open the file using pythonw instead of python. This is the preferred way to launch a final version of a PySimpleGUI program as there is no need for a Console window and it will be a much more "Windows-like" experience.

Floating toolbar

NOTE - Please look in the Demo Programs that use the newer Exec APIs. This Recipe uses an older technique to launch subprocesses. You'll find the Exec APIs documented in the main documentation and the Call Reference.

"Launchers" have come a long long ways since the early days of PySimpleGUI. This recipe directly calls subprocess.Popen. In 2020 a new set of APIs, the Exec APIs, were added to PySimpleGUI. These calls simplify the subprocess calls thus making them more approachable for newcomers to Python.

toolbar gray

You can easily change colors to match your background by changing a couple of parameters in the code.

toolbar black

    import PySimpleGUI as sg      
    import subprocess      
    import os      
    import sys      

     Demo_Toolbar - A floating toolbar with quick launcher     One cool PySimpleGUI demo. Shows borderless windows, grab_anywhere, tight button layout      
     You can setup a specific program to launch when a button is clicked, or use the Combobox to select a .py file found in the root folder, and run that file.  """      

    ROOT_PATH = './'      

    def Launcher():      

        def print(line):      


        namesonly = [f for f in os.listdir(ROOT_PATH) if f.endswith('.py') ]      

        sg.set_options(element_padding=(0,0), button_element_size=(12,1), auto_size_buttons=False)      
        layout =  [[sg.Combo(values=namesonly, size=(35,30), key='demofile'),      
                    sg.Button('Run', button_color=('white', '#00168B')),      
                    sg.Button('Program 1'),      
                    sg.Button('Program 2'),      
                    sg.Button('Program 3', button_color=('white', '#35008B')),      
                    sg.Button('EXIT', button_color=('white','firebrick3'))],      
                    [sg.T('', text_color='white', size=(50,1), key='output')]]      

        window = sg.Window('Floating Toolbar', layout, no_titlebar=True, keep_on_top=True)

        # ---===--- Loop taking in user input (events) --- #      
        while True:      
            (event, value) = window.read()      
            if event ==  'EXIT'  or event == sg.WIN_CLOSED:      
                break # exit button clicked      
            if event ==  'Program 1':      
                print('Run your program 1 here!')      
            elif event ==  'Program 2':      
                print('Run your program 2 here!')      
            elif event ==  'Run':      
                file = value['demofile']      
                print('Launching %s'%file)      
                ExecuteCommandSubprocess('python', os.path.join(ROOT_PATH, file))      

    def ExecuteCommandSubprocess(command, *args, wait=False):      
            if sys.platwindow == 'linux':      
                arg_string = ''      
                for arg in args:      
                     arg_string += ' '  + str(arg)      
                sp = subprocess.Popen(['python3'  + arg_string, ], shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)      
                sp = subprocess.Popen([command, list(args)], shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)      

            if wait:      
                out, err = sp.communicate()      
                if out:      
                if err:      
        except: pass      

    if __name__ == '__main__':