PyQt/网络/窗口配合异步Http/README.md

32 lines
1 KiB
Markdown
Raw Normal View History

2018-10-24 14:17:01 +08:00
# asyncio结合PyQt例子
### [Python3.5][PyQt5]
2018-10-24 14:18:07 +08:00
依赖库:<br/>
quamash对QT事件循环的封装替换https://github.com/harvimt/quamash<br/>
asynciohttps://docs.python.org/3/library/asyncio.html<br/>
aiohttphttps://aiohttp.readthedocs.io/en/stable/<br/>
2018-10-24 14:17:01 +08:00
1、在创建QApplication后随即设置替换事件循环loop
```python
app = QApplication(sys.argv)
loop = QEventLoop(app)
asyncio.set_event_loop(loop)
w = Window()
```
2、通过asyncio.ensure_future(函数(), loop=loop)来执行某个异步函数
Window  →→  initSession初始化session<br/>
 ↓<br/>
 ↓<br/>
下载按钮  →→  doDownload执行_doDownload方法<br/>
           ↓<br/>
           ↓<br/>
          session.get下载json数据进行解析<br/>
           ↓<br/>
           ↓<br/>
添加到界面  ←←  _doDownloadImage对单张图片进行下载
# 截图
![截图1](ScreenShot/1.gif)