6

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.

Robert Siemer
  • 32,405
  • 11
  • 84
  • 94
ArekBulski
  • 4,520
  • 4
  • 39
  • 61

1 Answers1

8

For Ubuntu:

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

(Source)

For Windows:

import ctypes
ctypes.windll.user32.LockWorkStation()

(Source)

Community
  • 1
  • 1
Stephen Rauch
  • 47,830
  • 31
  • 106
  • 135