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