ntchat/examples/quit_event.py
2022-08-27 20:30:03 +08:00

39 lines
856 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# -*- coding: utf-8 -*-
import sys
import time
import ntchat
def version_tuple(v):
return tuple(map(int, (v.split("."))))
if version_tuple(ntchat.__version__) < version_tuple('0.1.4'):
print("error: ntchat version required 0.1.4, use `pip install -U ntchat` to upgrade")
sys.exit()
wechat = ntchat.WeChat()
# 打开pc微信, smart: 是否管理已经登录的微信
wechat.open(smart=True)
global_quit_flag = False
# 微信进程关闭通知
@wechat.msg_register(ntchat.MT_RECV_WECHAT_QUIT_MSG)
def on_wechat_quit(wechat_instace):
print("###################")
global global_quit_flag
global_quit_flag = True
# 以下是为了让程序不结束如果有用于PyQt等有主循环消息的框架可以去除下面代码
while True:
if global_quit_flag:
break
time.sleep(0.5)
ntchat.exit_()
sys.exit()