想你课堂 发表于 2022-8-24 00:22:48

中秋佳节,阖家团圆

本帖最后由 想你课堂 于 2022-8-24 00:22 编辑

任务目标

1.给出一副图片,做背景;
2.输出一首中秋的诗词;


创意起源中秋节快到了,给各位朋友送上中秋的祝福,祝大家中秋快乐!作品展示


知识点

学习使用unihiker库显示图片、文字的方法


Unihiker库GUI类draw_image()方法显示图片

GUI类中的draw_image()方法可以实现在行空板屏幕上显示图片,在编程时,通过“对象.方法名()”的形式来实现功能,同时,此方法会返回一个图片对象,使用变量存储起来方便后续进行对象更新操作。

中秋图片


img = gui.draw_image(x=0,y=0, image='中秋.png')# 显示初始背景图为中秋

动手实践1、硬件搭建
通过USB连接线将行空板连接到计算机
2、程序编写

把图片放到同一个文件夹中。
import time
from unihiker import GUI # 导入unihiker库GUI模块
# 创建绘图窗口

gui = GUI() # 实例化GUI类
img = gui.draw_image(x=0,y=0, image='中秋.png')# 显示初始背景图为中秋
gui.draw_text(x=80, y=28, color="red", text="静夜思", font_size=20) # 在(80,28)坐标位显示文字“静夜思”,颜色为red,字体大小为20
gui.draw_text(x=60, y=63, color="black", text="【唐】 李白", font_size=15,)
gui.draw_text(x=50, y=88, color="orange", text="床前明月光,", font_size=20,)
gui.draw_text(x=50, y=128, color="pink", text="疑是地上霜。", font_size=20,)
gui.draw_text(x=50, y=168, color="red", text="举头望明月,", font_size=20,)
gui.draw_text(x=50, y=208, color="blue", text="低头思故乡。", font_size=20,)
gui.draw_text(x=30, y=248, color="red", text="你", font_size=20)
gui.draw_text(x=60, y=248, color="orange", text="好", font_size=20,)
gui.draw_text(x=90, y=248, color="yellow", text=",", font_size=20)
gui.draw_text(x=120, y=248, color="pink", text="行", font_size=20)
gui.draw_text(x=150, y=248, color="red", text="空", font_size=20)
gui.draw_text(x=180, y=248, color="blue", text="板", font_size=20)
gui.draw_text(x=210, y=248, color="pink", text="!", font_size=20)
gui.draw_text(x=60, y=278, color="yellow", text="2", font_size=20)
gui.draw_text(x=90, y=278, color="red", text="0", font_size=20)
gui.draw_text(x=120, y=278, color="blue", text="2", font_size=20)
gui.draw_text(x=150, y=278, color="pink", text="2", font_size=20)

while True:# 循环
    time.sleep(10)# delay1秒3、程序运行

STEP1:远程连接行空板

(1) 确认板子处于连接且开机状态

(2) 开启远程连接终端

(3) 连接行空板

(4)运行程序观察效果


问题发现:img = gui.draw_image(x=0,y=0, w=240, h=320, image='中秋.png')# 显示初始背景图为中秋
运行背景图片时,发现有白边,去掉了w=240, h=320。留待大家去发现。
页: [1]
查看完整版本: 中秋佳节,阖家团圆