对于Ubuntu: os.popen('gnome-screensaver-command --lock') (来源) 对于Windows: import ctypes ctypes.windll.user32.LockWorkStation() (Source)