Home > database >  How to freeze windows 10 screen with Python?
How to freeze windows 10 screen with Python?

Time:11-25

I made a GUI program that notifies me if I sit too much in front of the PC, it tells me to drink water or take a walk based on the task and time given, but that can be ignored and closed easily if I click X, I want it to be restricting and serious. So is there any python code or cmd command that I can include in the program that is able to freeze the entire windows screen for a period of time?

EDITED: If there's a way I can disable the mouse, would be great too.

Thank you in advance!

CodePudding user response:

You can do this with a mixture root.attributes() and root.protocol().

If you wanted a button to give you back control in your GUI, say after you had completed your tasks, you could use something like this:

import tkinter as tk

def foo():
    pass
root = tk.Tk()
root.attributes("-fullscreen", True, "-topmost", True)
root.protocol("WM_DELETE_WINDOW", foo)

but = tk.Button(root, text = "I have completed my tasks", command=root.destroy)
but.grid()

root.mainloop()

Or if you wanted a simple timer-activated screen that shuts off after a set time:

import tkinter as tk

root = tk.Tk()
root.attributes("-fullscreen", True, "-topmost", True, "-disabled", True)

time_interrupt = 5000 # Time screen is active in ms
root.after(time_interrupt, root.destroy)

root.mainloop()

Note these only work properly for a single screen, if you have multiple screens it may potentially work but you will likely need to add more code.

  • Related