zoukankan      html  css  js  c++  java
  • tkinter+高德api服务 实现天气查询

     1 # -*- coding:utf-8 -*-
     2 #weather_api
     3 import requests
     4 import json
     5 '''
     6 东城区:110101
     7 西城区:110102
     8 朝阳区:110105
     9 丰台区:110106
    10 '''
    11 
    12 def Weather_info(input_city):
    13     # city = ''
    14     weatherinfo_search = 'https://restapi.amap.com/v3/weather/weatherInfo?parameters'
    15     # if input_city == "东城区":
    16     #     city.join("110101")
    17     # elif input_city == "西城区":
    18     #     city.join("110102")
    19     # elif input_city == "朝阳区":
    20     #     city.join("110105")
    21     # elif input_city == "丰台区":
    22     #     city.join("110106")
    23     # else:
    24     #     print("城市未知")
    25     params = {'key':'cd1b11e803196aa2a3062f25',
    26               'city':input_city,
    27               'extensions':'base',
    28               'output':'JSON'}
    29     result = requests.get(url=weatherinfo_search,params=params)
    30     # print(result.status_code)
    31     # print(result.json())
    32     # print(result.text)
    33     # print(result.text[0])
    34     # print(json.dumps(result.json(),sort_keys=True,indent=4,ensure_ascii=False))
    35     lives = (result.json()["lives"])
    36     for lives_obj in lives:
    37         weather_result = lives_obj["weather"]
    38         weather_city = lives_obj["city"]
    39         print("城市:", weather_city)
    40         print("天气:",weather_result)
    41 
    42         return weather_result,weather_city
     1 # -*- coding:utf-8 -*-
     2 from tkinter import *
     3 import Weather_API
     4 
     5 
     6 # 实例化object,建立窗口window
     7 window = Tk()
     8 # 给窗口的可视化起名字
     9 window.title("天气查询")
    10 # 定窗口的大小(长 * 宽)
    11 window.geometry('500x300')  # 这里的乘是小x
    12 entry  = Entry(window)
    13 entry.pack()
    14 
    15 def search_weather():
    16     input_city = entry.get()
    17     print(input_city)
    18     Weather_API.Weather_info(input_city=input_city)
    19 Search_button = Button(window, text='查询', font=('Arial', 12), width=10, height=1, command=search_weather)
    20 
    21 Search_button.pack()
    24 window.mainloop()
    25
  • 相关阅读:
    商用 三色灯 显示屏 原理概述
    高速LVDS时序到底怎么看
    quartus qsys sdram IP 使用
    Avalon 总线 时序 介绍
    以太网 mac层传输 verilog 测试程序
    quartus15.1 下程程序 电脑蓝屏 解决方法
    vivado 波形保存以及arp
    quartus timequest 使用过程中的笔记
    Modelsim 仿真指令force用法
    开发笔记(一)Kintex
  • 原文地址:https://www.cnblogs.com/jiaown123/p/14744582.html
Copyright © 2011-2022 走看看