detect laptop open/close from within Python?

Chris Angelico rosuav at
Thu Apr 26 11:49:23 EDT 2018

On Fri, Apr 27, 2018 at 1:37 AM, Skip Montanaro
<skip.montanaro at> wrote:
> I'm going through a bout of RSI problems with my wrists, so klst night
> I refreshed an old typing watcher program I wrote a couple decades ago
> (there's a comment about Python 1.4 in the code!):
> It's far from perfect and I'm sure miles behind more modern stuff, but
> it does the trick for me.
> I noticed a feww minutes ago that when I opened my laptop it
> immediately locked the screen. It would be nice to get notified of
> open/close events on the laptop. Any idea if there is a signal I can
> catch (Ubuntu 17.10) or a Tk event I can respond to?

No idea if it'll work on your system, but on my laptop, there's a
pseudo-file /proc/acpi/button/lid/LID0/state that has whether the lid
is open or closed.


More information about the Python-list mailing list