Keep screen ON of window operating system when tkinter coded application ON

I have code in tkinter python for USART serial monitor application (.exe file). Problem is, I am not able to code for keep screen ON of window operating system when application ON. System screen goes OFF, if manually not perform any activity in system like mouse cursor movement or other, before complete of PC screen OFF time duration.

If I understand correctly, you’ll need to change the “Power & Sleep” settings of Windows.

This is 2nd option and I can not tell every user for change screen and sleep time into window setting while it should be default.

I want to do by code in python.

Consider i have done 10minute setting of sleep mode into window setting page. Now we play any video in PC and we found after 20 minutes our PC screen continue ON while manually mouse cursor not moved.

Same thing i want to do in our code, if application opened and user do not perform any task manually then screen should be ON till application opened.

Did you mean until application closed? In any case, I might try using tkinter to periodically simulate keypresses and/or mouse movements. I don’t know if either would keep screen on.

Did you mean until application closed?

In the end, the correct solution is to call this function: SetThreadExecutionState function (winbase.h) - Win32 apps | Microsoft Learn

There might be a portion wrapper somewhere, but you can easily call it via ctypes.

Thanks for your valuable support. I will try it.

Dear sir, Sorry for late reply. And thanks for solve problem.
I have done screen keep ON by key press at interval.