### Do Something here...
from datetime import datetime
last = 0 #Record the last time to do checking, for now, just put it to any number you want
while True:
now = datetime.now()
second = now.second
if now != second:
### Do checking here for example, a file called "quit_state.txt"
date = open("quit_state.txt",'r').read().strip() ### Strip the data
if date == "quit":
quit()
from pynput.keyboard import Key, Listener
import threading
import sys
def on_press(key):
global pause
if str(format(key))[1]=='`':
sys.exit()
def fun():
YOUR CODE HERE
threading.Thread(target=fun).start()
with Listener(
on_press=on_press) as listener:
listener.join()
你可以做taskkill/IMpythonw.exe/如果你只有一只Python在跑。把这个输入终端,或者在桌面或者任何你想要的地方创建一个链接。在
你可以做一个文件。pyw程序应该每隔1秒检查一次。如果文件发生更改,请在.pyw程序中运行
quit()
命令。但是不要每次勾选都检查它,因为它会失败,因为文件处于“更改”状态。在示例:
只需将文件数据更改为
quit
,程序就会停止您可以在脚本中包含线程以获取输入
这将在按“`”时退出代码 系统出口()将停止main thead,但您需要以fun()线程也结束来结束程序的方式进行管理
相关问题 更多 >
编程相关推荐