资源简介
使用PyQt5开发的天气预报查询代码。 Qt5 用 Designer设计界面,然后生成 python代码,做界面效率挺高的。

代码片段和文件信息
# -*- coding: utf-8 -*-
from PyQt5 import QtCore QtGui QtWidgets
from PyQt5.QtWidgets import QDialogQApplication
from PyQt5.QtGui import QIcon
import urllib.request
import gzip
import json
def get_weather_data(cityName) :
#city_name = input(‘请输入要查询的城市名称:‘)
url1 = ‘http://wthrcdn.etouch.cn/weather_mini?city=‘+urllib.parse.quote(cityName)
#网址1只需要输入城市名,网址2需要输入城市代码
weather_data = urllib.request.urlopen(url1).read()
#读取网页数据
weather_data = gzip.decompress(weather_data).decode(‘utf-8‘)
#解压网页数据
weather_dict = json.loads(weather_data)
#将json数据转换为dict数据
return weather_dict
def show_weather(weather_datam4Days):
weather_dict = weather_data
#将json数据转换为dict数据
if weather_dict.get(‘desc‘) == ‘invilad-citykey‘:
weather_str=‘你输入的城市名有误,或者天气中心未收录你所在城市‘
elif weather_dict.get(‘desc‘) ==‘OK‘:
forecast = weather_dict.get(‘data‘).get(‘forecast‘)
weather_str=‘城市:‘+weather_dict.get(‘data‘).get(‘city‘)+‘\n‘
weather_str=weather_str + ‘温度:‘ + weather_dict.get(‘data‘).get(‘wendu‘)+‘℃ ‘+‘\n‘
weather_str=weather_str + ‘感冒:‘ + weather_dict.get(‘data‘).get(‘ganmao‘) +‘\n‘
weather_str=weather_str + ‘风向:‘+forecast[0].get(‘fengxiang‘)+‘\n‘
wind_level=forecast[0].get(‘fengli‘)
tailor_str=wind_level[wind_level.index(‘[CDATA[‘)+7:wind_level.index(‘]]‘)]
weather_str=weather_str + ‘风级:‘+tailor_str+‘\n‘
#weather_str=weather_str + ‘风级:‘+forecast[0].get(‘fengli‘)+‘\n‘
weather_str=weather_str + ‘高温:‘+forecast[0].get(‘high‘)+‘\n‘
weather_str=weather_str + ‘低温:‘+forecast[0].get(‘low‘)+‘\n‘
weather_str=weather_str + ‘天气:‘+forecast[0].get(‘type‘)+‘\n‘
weather_str=weather_str + ‘日期:‘+forecast[0].get(‘date‘)+‘\n‘
weather_str=weather_str + ‘**********************************************‘+‘\n‘
if m4Days==1:
for i in range(15):
weather_str=weather_str +‘日期:‘+forecast[i].get(‘date‘)+‘\n‘
weather_str=weather_str +‘风向:‘+forecast[i].get(‘fengxiang‘)+‘\n‘
wind_level=forecast[i].get(‘fengli‘)
tailor_str=wind_level[wind_level.index(‘[CDATA[‘)+7:wind_level.index(‘]]‘)]
weather_str=weather_str +‘风级:‘+tailor_str+‘\n‘
#weather_str=weather_str +‘风级:‘+forecast[i].get(‘fengli‘)+‘\n‘
weather_str=weather_str +‘高温:‘+forecast[i].get(‘high‘)+‘\n‘
weather_str=weather_str +‘低温:‘+forecast[i].get(‘low‘)+‘\n‘
weather_str=weather_str +‘天气:‘+forecast[i].get(‘type‘)+‘\n‘
weather_str=weather_str +‘--------------------------‘+‘\n‘
weather_str=weather_str +‘**********************************************‘+‘\n‘
return weather_str
from ui_WeatherForecast import Ui_Form
class myWeather(QDialog Ui_Form):
global m4Days
global mStr
global mCityStr
def __init__(selfparent=None):
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 114518 2017-10-14 20:38 Mostly Sunny.ico
文件 7975 2017-10-15 12:58 MyWeather.py
文件 10016 2017-10-15 12:57 ui_WeatherForecast.py
相关资源
- 二级考试python试题12套(包括选择题和
- pywin32_python3.6_64位
- python+ selenium教程
- PycURL(Windows7/Win32)Python2.7安装包 P
- 英文原版-Scientific Computing with Python
- 7.图像风格迁移 基于深度学习 pyt
- 基于Python的学生管理系统
- A Byte of Python(简明Python教程)(第
- Python实例174946
- Python 人脸识别
- Python 人事管理系统
- 15个pyqt5项目
- 基于python-flask的个人博客系统
- 计算机视觉应用开发流程
- python 调用sftp断点续传文件
- python socket游戏
- 基于Python爬虫爬取天气预报信息
- python函数编程和讲解
- Python开发的个人博客
- 基于python的三层神经网络模型搭建
- python实现自动操作windows应用
- pyqt5动态加载ui文件,动态加载背景图
- python人脸识别(opencv)
- python 绘图(方形、线条、圆形)
- python疫情卡UN管控
- python 连连看小游戏源码
- 基于PyQt5的视频播放器设计
- 一个简单的python爬虫
- csv文件行列转换python实现代码
- Python操作Mysql教程手册
评论
共有 条评论