91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

資源簡介

使用PyQt5開發(fā)的天氣預(yù)報查詢代碼。 Qt5 用 Designer設(shè)計界面,然后生成 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)
????#網(wǎng)址1只需要輸入城市名,網(wǎng)址2需要輸入城市代碼
????weather_data?=?urllib.request.urlopen(url1).read()
????#讀取網(wǎng)頁數(shù)據(jù)
????weather_data?=?gzip.decompress(weather_data).decode(‘utf-8‘)
????#解壓網(wǎng)頁數(shù)據(jù)
????weather_dict?=?json.loads(weather_data)
????#將json數(shù)據(jù)轉(zhuǎn)換為dict數(shù)據(jù)
????return?weather_dict

def?show_weather(weather_datam4Days):
????weather_dict?=?weather_data?
????#將json數(shù)據(jù)轉(zhuǎn)換為dict數(shù)據(jù)
????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?+?‘風(fēng)向:‘+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?+?‘風(fēng)級:‘+tailor_str+‘\n‘

????????#weather_str=weather_str?+?‘風(fēng)級:‘+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?+‘風(fēng)向:‘+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?+‘風(fēng)級:‘+tailor_str+‘\n‘
????????????????#weather_str=weather_str?+‘風(fēng)級:‘+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

評論

共有 條評論