1.6. Skids 天气预报实例讲解

  • 如下图显示天气预报实例的最终程序
../../_images/skidsweather.png

1.6.1. 本章可以学到什么

  • 知识点
    • 积木块的基本操作
    • 函数的定义和调用
    • 变量的使用
    • 网络积木块的使用
    • 函数积木块的使用
    • 字符串显示积木块的使用
    • 编程的思路

1.6.2. 使用到的积木块列表

  • 逻辑列表中的条件积木块和循环积木块
../../_images/if.png

条件语句

代码:if False:

pass
../../_images/whileTrue.png

循环重复执行一些动作。

代码:while True:

  • SKkids分类中的屏幕列表的文本积木块
../../_images/turtle171.png

字符串显示

代码:text.draw(‘red’,0,0,0xff0000);

1.6.3. 实现思路

首先要让设备连接上网络需要使用网络接口进行联网操作,再使用httprequest接口库获取天气数据并用json库解析数据,最后使用文本接口显示数据。

1.6.4. 操作步骤

选择网络列表中的网络连接函数积木块

../../_images/skidsweather1.png

调用函数,获取天气数据并解析数据

../../_images/skidsweather2.png ../../_images/skidsweather3.png

加载到upycraft工具中

../../_images/skidsweather4.png

程序效果

../../_images/skidsweather5.png