search
HomeBackend DevelopmentPython TutorialPython implements scheduled pop-up reminders

I often use the computer and sit for hours at a time. I always forget the time, so I thought about finding a timer reminder software. I looked online and found a lot of them. I found a guard or something and installed it. Automatically lock screen countdown after the time is up. It has good features but it feels like it has too many features. I don’t know if you feel this way when you use software now. You originally want a very simple function, but the worst thing is that you have installed a lot of software with a lot of functions but no one you use.

Actually, what I want is to pop up a window to prompt me to take a rest after the time is up. Later I thought I might as well make one myself. Of course, the Python language is preferred.时 First of all, the specific code of time pop -up window is required:

The program uses its own Tkinter does not need to install the main functions of other packaging programs: 1. Automatically timing after startup 2. After the timing is completed, the pop -up window is prompted ( The default time is 30 minutes) 3. Click OK and restart the timer

There are some problems with the program: 1. The interface is simple and unrefined (but I think the function is achieved first) 2. The timer cannot be automatically stopped during sleep

# -*- coding: utf-8 -*-
import time, sys
# 判断python的版本然后import对应的模块
if sys.version < &#39;3&#39;:
from Tkinter import *
else:
from tkinter import *
mydelaymin = 30 #窗口提示的延迟时间,以分钟计
#------------------def-------------------
def showMessage():
#show reminder message window
root = Tk()  #建立根窗口
#root.minsize(500, 200)   #定义窗口的大小
#root.maxsize(1000, 400)  #不过定义窗口这个功能我没有使用
root.withdraw()  #hide window
#获取屏幕的宽度和高度,并且在高度上考虑到底部的任务栏,为了是弹出的窗口在屏幕中间
screenwidth = root.winfo_screenwidth()
screenheight = root.winfo_screenheight() - 100 
root.resizable(False,False)
#添加组件
root.title("Warning!!")
frame = Frame(root, relief=RIDGE, borderwidth=3)
frame.pack(fill=BOTH, expand=1) #pack() 放置组件若没有则组件不会显示
#窗口显示的文字、并设置字体、字号
label = Label(frame, text="You have been working 30 minutes! Please have a break!!", \
font="Monotype\ Corsiva -20 bold")
label.pack(fill=BOTH, expand=1)
#按钮的设置
button = Button(frame, text="OK", font="Cooper -25 bold", fg="red", command=root.destroy)
button.pack(side=BOTTOM)
root.update_idletasks()
root.deiconify() #now the window size was calculated
root.withdraw() #hide the window again 防止窗口出现被拖动的感觉 具体原理未知?
root.geometry(&#39;%sx%s+%s+%s&#39; % (root.winfo_width() + 10, root.winfo_height() + 10, 
(screenwidth - root.winfo_width())/2, (screenheight - root.winfo_height())/2))
root.deiconify()
root.mainloop()
#showMessage()
while True:
time.sleep(mydelaymin*60) #参数为秒
showMessage()

If Under win, you may need to consider how to run it automatically.

I am using a batch file. The details are as follows:

File name: rest_python.bat

The content is simple, just one line (if there are multiple python versions, please modify it):

Java code

python E:\rest.py

At the same time, a file is needed to run this batch file in the background . It's a bit troublesome. If there is an easier way, please share it.

The file name is: silent_bat.vbe

The content is as follows:

Java code

set ws=wscript.createobject("wscript.shell")  
ws.run"E:\rest_python.bat /start", 0

Then drag the silent_bat.vbe file into the startup folder. (You can also use shortcuts)

A few points to note: The program uses python2.7 system win7.

                                                                                                                                                                                                                                                                 to be processed will need to be changed based on where your files are stored.动 Remember to join the startup folder.

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Python's Execution Model: Compiled, Interpreted, or Both?Python's Execution Model: Compiled, Interpreted, or Both?May 10, 2025 am 12:04 AM

Pythonisbothcompiledandinterpreted.WhenyourunaPythonscript,itisfirstcompiledintobytecode,whichisthenexecutedbythePythonVirtualMachine(PVM).Thishybridapproachallowsforplatform-independentcodebutcanbeslowerthannativemachinecodeexecution.

Is Python executed line by line?Is Python executed line by line?May 10, 2025 am 12:03 AM

Python is not strictly line-by-line execution, but is optimized and conditional execution based on the interpreter mechanism. The interpreter converts the code to bytecode, executed by the PVM, and may precompile constant expressions or optimize loops. Understanding these mechanisms helps optimize code and improve efficiency.

What are the alternatives to concatenate two lists in Python?What are the alternatives to concatenate two lists in Python?May 09, 2025 am 12:16 AM

There are many methods to connect two lists in Python: 1. Use operators, which are simple but inefficient in large lists; 2. Use extend method, which is efficient but will modify the original list; 3. Use the = operator, which is both efficient and readable; 4. Use itertools.chain function, which is memory efficient but requires additional import; 5. Use list parsing, which is elegant but may be too complex. The selection method should be based on the code context and requirements.

Python: Efficient Ways to Merge Two ListsPython: Efficient Ways to Merge Two ListsMay 09, 2025 am 12:15 AM

There are many ways to merge Python lists: 1. Use operators, which are simple but not memory efficient for large lists; 2. Use extend method, which is efficient but will modify the original list; 3. Use itertools.chain, which is suitable for large data sets; 4. Use * operator, merge small to medium-sized lists in one line of code; 5. Use numpy.concatenate, which is suitable for large data sets and scenarios with high performance requirements; 6. Use append method, which is suitable for small lists but is inefficient. When selecting a method, you need to consider the list size and application scenarios.

Compiled vs Interpreted Languages: pros and consCompiled vs Interpreted Languages: pros and consMay 09, 2025 am 12:06 AM

Compiledlanguagesofferspeedandsecurity,whileinterpretedlanguagesprovideeaseofuseandportability.1)CompiledlanguageslikeC arefasterandsecurebuthavelongerdevelopmentcyclesandplatformdependency.2)InterpretedlanguageslikePythonareeasiertouseandmoreportab

Python: For and While Loops, the most complete guidePython: For and While Loops, the most complete guideMay 09, 2025 am 12:05 AM

In Python, a for loop is used to traverse iterable objects, and a while loop is used to perform operations repeatedly when the condition is satisfied. 1) For loop example: traverse the list and print the elements. 2) While loop example: guess the number game until you guess it right. Mastering cycle principles and optimization techniques can improve code efficiency and reliability.

Python concatenate lists into a stringPython concatenate lists into a stringMay 09, 2025 am 12:02 AM

To concatenate a list into a string, using the join() method in Python is the best choice. 1) Use the join() method to concatenate the list elements into a string, such as ''.join(my_list). 2) For a list containing numbers, convert map(str, numbers) into a string before concatenating. 3) You can use generator expressions for complex formatting, such as ','.join(f'({fruit})'forfruitinfruits). 4) When processing mixed data types, use map(str, mixed_list) to ensure that all elements can be converted into strings. 5) For large lists, use ''.join(large_li

Python's Hybrid Approach: Compilation and Interpretation CombinedPython's Hybrid Approach: Compilation and Interpretation CombinedMay 08, 2025 am 12:16 AM

Pythonusesahybridapproach,combiningcompilationtobytecodeandinterpretation.1)Codeiscompiledtoplatform-independentbytecode.2)BytecodeisinterpretedbythePythonVirtualMachine,enhancingefficiencyandportability.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.