PyQt5+requests实现一个车票查询工具,供大家参考,具体内容如下
结构图
![](https://upload-images.jianshu.io/upload_images/13406307-e31ffc365dcec2ee.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
效果图
![](https://upload-images.jianshu.io/upload_images/13406307-47bb058561749a23.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
思路
1、search(QPushButton)点击信号(clicked)连接到自定义的槽函数(event.search)
2、槽函数(event.search)接收四个参数:QTableWidget对象的引用、两个QLabel中的内容(站台名称)、QDateEdit格式化日期
3、槽函数(event.search)调用爬虫类(TrainService)获取车次信息,添加到QTableWidget对象中。
代码
1、ui.py(ui界面)
![](https://upload-images.jianshu.io/upload_images/13406307-c07479e426d630b6.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
2、EventClass.py(自定义槽函数类)
![](https://upload-images.jianshu.io/upload_images/13406307-e36faf0245b2ecde.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
3、TrainService.py(爬虫类)
![](https://upload-images.jianshu.io/upload_images/13406307-9d5a4fe25603a10b.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
.
需要先跑 TrainService.py 获取到站点对应的代码信息code.json
然后在执行 ui.py