WxPython 4.0 以后不用wx.lib.pubsub 来做消息通讯了, 改用 pubsub , 如果继续用 wx.lib.pubsub , 会有以下警告提示:
>>> from wx.lib.pubsub import pub
Warning (from warnings module):
File "D:\Python\Python37\lib\site-packages\wx\lib\pubsub\__init__.py", line 25
wx.wxPyDeprecationWarning)
wxPyDeprecationWarning: wx.lib.pubsub has been deprecated, plese migrate your code to use pypubsub, available on PyPI.
>>>
pip install pypubsub
对照pubsub文档,原理一样,折腾改了代码,以下贡献个例子。
# encoding: utf-8
"""
@author: 陈年椰子
@contact: hndm@qq.com
@version: 1.0
@file: wxpub.py
@time: 2019/6/13 0013 9:56
说明 WxPython 界面利用pubsub与线程通讯的例子
"""
import wx
from pubsub import pub
from time import sleep
import threading
import sys
# 耗时长的代码
def workproc():
sum_x = 0
for i in range(1, 101):
sum_