If you look at the source code you will see the functions grab_keyboard_and_mouse()
and ungrab_keyboard_and_mouse()
, which do the locking and unlocking.
The core locking and unlocking functions are done by calling the GTK library functions gdk_pointer_grab()
and gdk_keyboard_grab()
and their ..._ungrab()
equivalents.
You would need to make these functions callable from Python, but I don't know if that is a simple task or not. Alternatively, maybe you can find a program which puts up a message box with some input fields and buttons, like an extended xmessage
, but locking the screen while it's active.