'shut off screen using pygame

I'm using pygame to build a mockup of a home automation touch screen application. I would like the screen to shut off if the touch screen has been inactive for a certain period (~5 min), all the while the program continues to update the screen.

Is there anything built into pygame to allow this?

Would tkinter have been a better choice?



Solution 1:[1]

I found the following code that works for me.

I used pip3 install python3-xlib to install Python xlib. Then the following code was useful.

The only remain thing to do, I need to find a way to trigger it after a period of inactivity.

#!/usr/bin/python
# -*- coding:UTF-8 -*-

import time
import subprocess
from Xlib import X
from Xlib.display import Display
display = Display(':0')
root = display.screen().root
root.grab_pointer(True,
       X.ButtonPressMask | X.ButtonReleaseMask | X.PointerMotionMask,
       X.GrabModeAsync, X.GrabModeAsync, 0, 0, X.CurrentTime)
root.grab_keyboard(True,
       X.GrabModeAsync, X.GrabModeAsync, X.CurrentTime)
subprocess.call('xset dpms force off'.split())

p = subprocess.Popen('xset dpms force off'.split())
time.sleep(1)
while True:
   print (display.next_event())
   p.terminate()
   break

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 user3808752