資源簡介
Python 天氣查詢 示例源碼
代碼片段和文件信息
from?tkinter?import?*
import?urllib.request
import?gzip
import?json
from?tkinter?import?messagebox
root?=?Tk()
def?main():
????#輸入窗口
????root.title(‘天氣查詢‘)#窗口標(biāo)題
????Label(roottext?=?‘請輸入城市‘).grid(row=0column=0)#設(shè)置標(biāo)簽并調(diào)整位置
????enter?=?Entry(root)#輸入框
????enter.grid(row?=?0column=1padx?=?20?pady?=?20)#調(diào)整位置
????enter.delete(0END)#清空輸入框
????enter.insert(0‘綿陽‘)#設(shè)置默認(rèn)文本
????#enter_text?=?enter.get()#獲取輸入框的內(nèi)容5
????
????running?=?1
????def?get_weather_data()?:#獲取網(wǎng)站數(shù)據(jù)
????????city_name?=?enter.get()#獲取輸入框的內(nèi)容
????????url1?=?‘http://wthrcdn.etouch.cn/weather_mini?city=‘+urllib.parse.quote(city_name)
????????url2?=?‘http://wthrcdn.etouch.cn/weather_mini?citykey=101010100‘
????????#網(wǎng)址1只需要輸入城市名,網(wǎng)址2需要輸入城市代碼
????????#print(url1)
????????weather_data?=?urllib.request.urlop
評論
共有 條評論