Search code examples
pythonubuntuauthenticationlockscreen

Invoking the lock screen using python


How can I bring up the lock screen from within a python app? I would like the application to do that for me instead of pressing the Ctrl-Alt-L separately.


Solution

  • For Ubuntu:

    os.popen('gnome-screensaver-command --lock')
    

    (Source)

    For Windows:

    import ctypes
    ctypes.windll.user32.LockWorkStation()
    

    (Source)