eight天气-您的智能天气助理

import easygui
import turtle
from tkinter import *
import urllib.request
import gzip
import json
from tkinter import messagebox

def eight():
    turtle.setup(1000, 800)
    turtle.speed(6)
    turtle.colormode(255)
    turtle.color((0, 0, 0), (60, 100, 30))
    turtle.penup()
    turtle.goto(0, (-200))
    turtle.pendown()
    turtle.begin_fill()
    turtle.circle(200)
    turtle.end_fill()
    turtle.pensize(2)
    turtle.penup()
    turtle.goto(190, (-60))
    turtle.pendown()
    turtle.goto((-190), (-60))
    turtle.penup()
    turtle.goto(190, 60)
    turtle.pendown()
    turtle.goto((-190), 60)
    turtle.penup()
    turtle.goto(60, 190)
    turtle.pendown()
    turtle.goto(60, (-190))
    turtle.penup()
    turtle.goto((-60), 190)
    turtle.pendown()
    turtle.goto((-60), (-190))
    turtle.penup()
    turtle.pensize(1)
    turtle.goto(20, 198)
    turtle.penup()
    turtle.goto(0, 200)
    turtle.pendown()
    turtle.color((0, 0, 0), (60, 80, 30))
    turtle.begin_fill()
    a = 1
    turtle.speed(0)
    for i in range(120):
        if (0 <= i < 30 or 60 <= i <= 90):
            a = (a + 0.04)
            turtle.left(3)
            turtle.forward(a)
        else:
            a = (a - 0.04)
            turtle.left(3)
            turtle.forward(a)
    turtle.penup()
    turtle.end_fill()

    turtle.color((0, 0, 0), (255, 255, 255))
    turtle.goto(11, 240)
    turtle.begin_fill()
    turtle.pendown()
    turtle.circle(5)
    turtle.end_fill()
    turtle.penup()
    turtle.end_fill()
    turtle.color((0, 0, 0), (255, 255, 255))
    turtle.goto((-11), 240)
    turtle.begin_fill()
    turtle.pendown()
    turtle.circle(5)
    turtle.end_fill()
    turtle.penup()

    turtle.color((0, 0, 0), (0, 0, 0))
    turtle.goto(10, 240)
    turtle.begin_fill()
    turtle.pendown()
    turtle.circle(3)
    turtle.end_fill()
    turtle.penup()
    turtle.end_fill()
    turtle.color((0, 0, 0), (0, 0, 0))
    turtle.goto((-10), 240)
    turtle.begin_fill()
    turtle.pendown()
    turtle.circle(3)
    turtle.end_fill()
    turtle.penup()
    turtle.color((0, 0, 0), (60, 80, 30))
    turtle.goto((-120), 150)
    turtle.pendown()
    turtle.setheading(30)
    turtle.begin_fill()
    a = 0.3
    for i in range(120):
        if (0 <= i < 30 or 60 <= i <= 90):
            a = (a + 0.06)
            turtle.left(3)
            turtle.forward(a)
        else:
            a = (a - 0.06)
            turtle.left(3)
            turtle.forward(a)
    turtle.end_fill()
    turtle.penup()
    turtle.goto(120, 150)
    turtle.pendown()
    turtle.setheading((-30))
    a = 0.3
    turtle.begin_fill()
    for i in range(120):
        if (0 <= i < 30 or 60 <= i <= 90):
            a = (a + 0.06)
            turtle.left(3)
            turtle.forward(a)
        else:
            a = (a - 0.06)
            turtle.left(3)
            turtle.forward(a)
    turtle.penup()
    turtle.end_fill()
    turtle.goto((-120), (-160))
    turtle.pendown()
    turtle.setheading((-210))
    turtle.begin_fill()
    a = 0.5
    for i in range(120):
        if (0 <= i < 30 or 60 <= i <= 90):
            a = (a + 0.03)
            turtle.left(3)
            turtle.forward(a)
        else:
            a = (a - 0.03)
            turtle.left(3)
            turtle.forward(a)
    turtle.penup()
    turtle.end_fill()
    turtle.goto(120, (-160))
    turtle.pendown()
    turtle.setheading(210)
    turtle.begin_fill()
    a = 0.5
    for i in range(120):
        if (0 <= i < 30 or 60 <= i <= 90):
            a = (a + 0.03)
            turtle.left(3)
            turtle.forward(a)
        else:
            a = (a - 0.03)
            turtle.left(3)
            turtle.forward(a)
    turtle.end_fill()
    turtle.penup()
    turtle.goto(0, (-200))
    turtle.setheading(0)
    turtle.pendown()

    turtle.begin_fill()
    turtle.forward(10)
    turtle.setheading((-105))
    turtle.forward(30)
    turtle.setheading(105)
    turtle.forward(30)
    turtle.setheading(0)
    turtle.forward(10)
    turtle.end_fill()
    turtle.hideturtle()
    turtle.done()

#欢迎
easygui.msgbox('Hello,我是eight,您的私人天气助理.')
eight()
easygui.msgbox('提示:本作品有Hello_World制作,版权所有!')
easygui.msgbox('欢迎使用eight天气!')

#main
root = Tk()
def main():
    # 输入窗口
    root.title('eight天气')  # 窗口标题
    Label(root, text='请输入城市(市级)').grid(row=0, column=0)  # 设置标签并调整位置
    enter = Entry(root)  # 输入框
    enter.grid(row=0, column=1, padx=20, pady=20)  # 调整位置
    enter.insert(0, '请输入城市(市级)')  # 设置默认文本
    enter.delete(0, END)  # 清空输入框
    # enter_text = enter.get()#获取输入框的内容
    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.urlopen(url1).read()
        # 读取网页数据
        weather_data = gzip.decompress(weather_data).decode('utf-8')
        # 解压网页数据
        weather_dict = json.loads(weather_data)
        # 将json数据转换为dict数据
        if weather_dict.get('desc') == 'invilad-citykey':
            print(messagebox.askokcancel("xing", "你输入的城市名有误,或者天气中心未收录你所在城市"))
        else:
            # print(messagebox.askokcancel('xing','bingguo'))
            show_data(weather_dict, city_name)
 
    def show_data(weather_dict, city_name):  # 显示数据
        forecast = weather_dict.get('data').get('forecast')  # 获取数据块
        root1 = Tk()  # 副窗口
        root1.geometry('650x280')  # 修改窗口大小
        root1.title('eight天气:' + city_name + '天气状况')  # 副窗口标题
 
        # 设置日期列表
        for i in range(5):  # 将每一天的数据放入列表中
            LANGS = [(forecast[i].get('date'), '日期'),
                     (forecast[i].get('fengxiang'), '风向'),
                     (str(forecast[i].get('fengji')), '风级'),
                     (forecast[i].get('high'), '最高温'),
                     (forecast[i].get('low'), '最低温'),
                     (forecast[i].get('type'), '天气')]
            group = LabelFrame(root1, text='天气状况', padx=0, pady=0)  # 框架
            group.pack(padx=11, pady=0, side=LEFT)  # 放置框架
            for lang, value in LANGS:  # 将数据放入框架中
                c = Label(group, text=value + ': ' + lang)
                c.pack(anchor=W)
        Label(root1, text='今日' + weather_dict.get('data').get('ganmao'),
              fg='green').place(x=40, y=20, height=40)  # 温馨提示
        Label(root1, text="好好学习,天天向上!", fg="green", bg="yellow").place(x=10, y=255, width=125,height=20)  # 作者网站
        Button(root1, text='确认并退出', width=10, command=root1.quit).place(x=500, y=230, width=80, height=40)  # 退出按钮
        root1.mainloop()
 
    # 布置按键
    Button(root, text="确认", width=10, command=get_weather_data) \
        .grid(row=3, column=0, sticky=W, padx=10, pady=5)
    Button(root, text='退出', width=10, command=root.quit) \
        .grid(row=3, column=1, sticky=E, padx=10, pady=5)
    if running == 1:
        root.mainloop()

if __name__ == '__main__':
    main()

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值