为了不把小孩子的背弄垮。
为了减少找书压力。
为了快速预习下一天的功课。
为了快速复习下一天的功课。
我设计了这个。
步骤1 设计图案
步骤2 编程
代码
import time
import requests
import datetime
from unihiker import GUI
from pinpong.board import Board
from pinpong.board import NeoPixel
from pinpong.board import Board,Pin
from pinpong.extension.unihiker import *
from pinpong.libs.dfrobot_speech_synthesis import DFRobot_SpeechSynthesis_I2C
# 自定义函数
def QingPing():
一.config(text="")
二.config(text="")
三.config(text="")
四.config(text="")
五.config(text="")
六.config(text="")
七.config(text="")
八.config(text="")
九.config(text="")
十.config(text="")
t1.config(text="")
t2.config(text="")
t3.config(text="")
time2.config(text="")
text2.config(text="")
t4.config(text="")
t5.config(text="")
def ZhouLiu():
t1.config(text="")
t2.config(text="")
t3.config(text="")
QingPing()
九.config(text=" 到周六了,")
十.config(text="先好好休息放松一下吧!!")
text2.config(text="休息好了再努力学习哦!")
np1.clear()
time.sleep(0.01)
p_gravitysynthesis.speak("到周六了,先好好休息放松一下吧!!休息好了再努力学习哦!")
def ZhouRi():
t1.config(text="")
t2.config(text="")
t3.config(text="")
QingPing()
九.config(text=" 到周日了,")
十.config(text="好好休息放松一下吧!")
text2.config(text="记得检查作业是否全部完成哦!")
np1.clear()
time.sleep(0.01)
p_gravitysynthesis.speak("到周日了,好好休息放松一下吧!记得检查作业是否全部完成哦!")
def ZhouWu():
t1.config(text="")
t2.config(text="")
t3.config(text="")
十.config(text="")
九.config(text="")
time2.config(text="")
一.config(text="第一节:综合实践")
二.config(text="第二节:语文")
三.config(text="第三节:音乐")
四.config(text="第四节:足球")
五.config(text="第五节:体育与健康")
六.config(text="第六节:信息科技")
七.config(text="周")
np1.range_color(0,1,0x000000)
np1.range_color(2,3,0x00FF00)
np1.range_color(11,12,0x00FFFF)
np1.range_color(13,15,0xCC33CC)
np1.range_color(4,10,0x000000)
time.sleep(1)
p_gravitysynthesis.speak("第一节:综合实践")
p_gravitysynthesis.speak("第二节:语文")
p_gravitysynthesis.speak("第三节:音乐")
p_gravitysynthesis.speak("第四节:足球")
p_gravitysynthesis.speak("第五节:体育与健康")
p_gravitysynthesis.speak("第六节:信息科技")
def ZhouYi():
t1.config(text="")
t2.config(text="")
t3.config(text="")
QingPing()
time2.config(text="")
一.config(text="第一节:数学")
二.config(text="第二节:语文")
三.config(text="第三节:语文")
四.config(text="第四节:英语")
五.config(text="第五节:体育与健康")
六.config(text="第六节:美术")
七.config(text="周")
np1.range_color(0,1,0x00FF00)
np1.range_color(2,3,0xFF0000)
np1.range_color(4,5,0xFFFF00)
np1.range_color(6,8,0x0000FF)
np1.range_color(9,15,0x000000)
time.sleep(1)
p_gravitysynthesis.speak("第一节:数学")
p_gravitysynthesis.speak("第二节:语文")
p_gravitysynthesis.speak("第三节:语文")
p_gravitysynthesis.speak("第四节:英语")
p_gravitysynthesis.speak("第五节:体育与健康")
p_gravitysynthesis.speak("第六节:美术")
def ZhouEr():
t1.config(text="")
t2.config(text="")
t3.config(text="")
time2.config(text="")
一.config(text="第一节:语文")
二.config(text="第二节:数学")
三.config(text="第三节:班队活动")
四.config(text="第四节:综合实践")
五.config(text="第五节:体育与健康")
六.config(text="第六节:信息科技")
七.config(text="周")
np1.range_color(0,1,0xFF0000)
np1.range_color(2,3,0x00FF00)
np1.range_color(11,12,0x00FFFF)
np1.range_color(13,15,0xCC33CC)
np1.range_color(4,10,0x000000)
time.sleep(1)
p_gravitysynthesis.speak("第一节:语文")
p_gravitysynthesis.speak("第二节:数学")
p_gravitysynthesis.speak("第三节:班队活动")
p_gravitysynthesis.speak("第四节:综合实践")
p_gravitysynthesis.speak("第五节:体育与健康")
p_gravitysynthesis.speak("第六节:信息科技")
def ZhouSan():
t1.config(text="")
t2.config(text="")
t3.config(text="")
time2.config(text="")
一.config(text="第一节:数学")
二.config(text="第二节:语文")
三.config(text="第三节:英语")
四.config(text="第四节:美术")
五.config(text="第五节:书法")
六.config(text="第六节:科学")
七.config(text="周")
np1.range_color(0,1,0xFF0000)
np1.range_color(2,3,0x00FF00)
np1.range_color(4,5,0xFFFF00)
np1.range_color(9,10,0xFF9900)
np1.range_color(6,8,0x000000)
np1.range_color(11,15,0x000000)
time.sleep(1)
p_gravitysynthesis.speak("第一节:数学")
p_gravitysynthesis.speak("第二节:语文")
p_gravitysynthesis.speak("第三节:英语")
p_gravitysynthesis.speak("第四节:美术")
p_gravitysynthesis.speak("第五节:书法")
p_gravitysynthesis.speak("第六节:科学")
def ZhouSi():
t1.config(text="")
t2.config(text="")
t3.config(text="")
time2.config(text="")
一.config(text="第一节:语文")
二.config(text="第二节:数学")
三.config(text="第三节:音乐")
四.config(text="第四节:校本课程")
五.config(text="第五节:体育与健康")
六.config(text="第六节:科学")
七.config(text="周")
np1.range_color(0,1,0xFF0000)
np1.range_color(2,3,0x00FF00)
np1.range_color(4,5,0x000000)
np1.range_color(9,10,0xFF9900)
np1.range_color(6,8,0x000000)
np1.range_color(11,15,0x000000)
time.sleep(1)
p_gravitysynthesis.speak("第一节:语文")
p_gravitysynthesis.speak("第二节:数学")
p_gravitysynthesis.speak("第三节:音乐")
p_gravitysynthesis.speak("第四节:校本课程")
p_gravitysynthesis.speak("第五节:体育与健康")
p_gravitysynthesis.speak("第六节:科学")
# 事件回调函数
def button_click4():
QingPing()
text1.config(text="欢迎来到智能书架!")
text2.config(text="")
t1=u_gui.draw_text(text=(data["city"]),x=20,y=60,font_size=15, color="#0000FF")
t2=u_gui.draw_text(text=(data["wea"]),x=80,y=60,font_size=15, color="#0000FF")
t3=u_gui.draw_text(text=(str((data["tem"])) + str(" ℃")),x=120,y=60,font_size=15, color="#0000FF")
t4=u_gui.draw_text(text=(str("最高:") + str((str((data["tem1"])) + str(" ℃,")))),x=5,y=80,font_size=15, color="#0000FF")
t5=u_gui.draw_text(text=(str("最低:") + str((str((data["tem2"])) + str(" ℃")))),x=120,y=80,font_size=15, color="#0000FF")
np1.range_color(0,29,0x000000)
p_gravitysynthesis.speak("你好!欢迎来到智能书架!")
p_gravitysynthesis.speak("现在时间是:")
p_gravitysynthesis.speak(time.strftime("%Y/%m/%d %H:%M:%S"))
p_gravitysynthesis.speak("现在为你播报天气情况:")
p_gravitysynthesis.speak((data["city"]))
p_gravitysynthesis.speak((data["wea"]))
p_gravitysynthesis.speak((str((data["tem"])) + str(" ℃")))
p_gravitysynthesis.speak((str("最高气温") + str((str((data["tem1"])) + str(" ℃")))))
p_gravitysynthesis.speak((str("最低气温") + str((str((data["tem2"])) + str(" ℃")))))
def button_click1():
t1.config(text="")
t2.config(text="")
t3.config(text="")
text2.config(text="")
QingPing()
week = datetime.datetime.now().isoweekday()
if (week == 1):
ZhouRi()
if (week == 2):
ZhouYi()
八.config(text="一")
if (week == 3):
ZhouEr()
八.config(text="二")
if (week == 4):
ZhouSan()
八.config(text="三")
if (week == 5):
ZhouSi()
八.config(text="四")
if (week == 6):
ZhouWu()
八.config(text="五")
if (week == 7):
ZhouLiu()
def button_click3():
t1.config(text="")
t2.config(text="")
t3.config(text="")
text2.config(text="")
QingPing()
week = datetime.datetime.now().isoweekday()
if (week == 1):
ZhouEr()
八.config(text="二")
if (week == 2):
ZhouSan()
八.config(text="三")
if (week == 3):
ZhouSi()
八.config(text="四")
if (week == 4):
ZhouWu()
八.config(text="五")
if (week == 5):
ZhouLiu()
if (week == 6):
ZhouRi()
if (week == 7):
ZhouYi()
八.config(text="一")
def button_click2():
t1.config(text="")
t2.config(text="")
t3.config(text="")
text2.config(text="")
QingPing()
week = datetime.datetime.now().isoweekday()
if (week == 1):
ZhouYi()
八.config(text="一")
if (week == 2):
ZhouEr()
八.config(text="二")
if (week == 3):
ZhouSan()
八.config(text="三")
if (week == 4):
ZhouSi()
八.config(text="四")
if (week == 5):
ZhouWu()
八.config(text="五")
if (week == 6):
ZhouLiu()
if (week == 7):
ZhouRi()
u_gui=GUI()
Board().begin()
text1=u_gui.draw_text(text="欢迎来到智能书架",x=10,y=0,font_size=16, color="#0000FF")
text2=u_gui.draw_text(text="",x=0,y=150,font_size=15, color="#0000FF")
url = (str("http://v1.yiketianqi.com/api?unescape=1&version=v61&appid=99328439&appsecret=TW3D2VlT&unescape=1&city=") + str("椒江"))
response = requests.get(url)
data = response.json()
t1=u_gui.draw_text(text=(data["city"]),x=20,y=60,font_size=15, color="#0000FF")
t2=u_gui.draw_text(text=(data["wea"]),x=80,y=60,font_size=15, color="#0000FF")
t3=u_gui.draw_text(text=(str((data["tem"])) + str(" ℃")),x=120,y=60,font_size=15, color="#0000FF")
t4=u_gui.draw_text(text=(str("最高:") + str((str((data["tem1"])) + str(" ℃,")))),x=5,y=80,font_size=15, color="#0000FF")
t5=u_gui.draw_text(text=(str("最低:") + str((str((data["tem2"])) + str(" ℃")))),x=120,y=80,font_size=15, color="#0000FF")
一=u_gui.draw_text(text="",x=0,y=85,font_size=16, color="#0000FF")
二=u_gui.draw_text(text="",x=0,y=110,font_size=15, color="#0000FF")
三=u_gui.draw_text(text="",x=0,y=135,font_size=16, color="#0000FF")
四=u_gui.draw_text(text="",x=0,y=160,font_size=15, color="#0000FF")
五=u_gui.draw_text(text="",x=0,y=185,font_size=16, color="#0000FF")
六=u_gui.draw_text(text="",x=0,y=210,font_size=15, color="#0000FF")
七=u_gui.draw_text(text="",x=100,y=235,font_size=16, color="#0000FF")
八=u_gui.draw_text(text="",x=120,y=235,font_size=15, color="#0000FF")
九=u_gui.draw_text(text="",x=20,y=90,font_size=15, color="#0000FF")
十=u_gui.draw_text(text="",x=0,y=120,font_size=15, color="#0000FF")
time2=u_gui.draw_text(text=time.strftime("%Y/%m/%d %H:%M:%S"),x=0,y=30,font_size=15, color="#0000FF")
B1=u_gui.add_button(text="昨天",x=30,y=280,w=40,h=30,onclick=button_click1)
B2=u_gui.add_button(text="今天",x=80,y=280,w=40,h=30,onclick=button_click2)
B3=u_gui.add_button(text="明天",x=130,y=280,w=40,h=30,onclick=button_click3)
B4=u_gui.add_button(text="复位",x=180,y=280,w=40,h=30,onclick=button_click4)
np1 = NeoPixel(Pin((Pin.P24)),16)
np1.brightness(128)
np1.brightness(255)
p_gravitysynthesis = DFRobot_SpeechSynthesis_I2C()
p_gravitysynthesis.begin(p_gravitysynthesis.V2)
p_gravitysynthesis.speak("你好!欢迎来到智能书架!")
p_gravitysynthesis.speak("现在时间是:")
p_gravitysynthesis.speak(time.strftime("%Y/%m/%d %H:%M:%S"))
p_gravitysynthesis.speak("现在为你播报天气情况:")
p_gravitysynthesis.speak((data["city"]))
p_gravitysynthesis.speak((data["wea"]))
p_gravitysynthesis.speak((str((data["tem"])) + str(" ℃")))
p_gravitysynthesis.speak((str("最高气温") + str((str((data["tem1"])) + str(" ℃")))))
p_gravitysynthesis.speak((str("最低气温") + str((str((data["tem2"])) + str(" ℃")))))
while True:
time2.config(text=time.strftime("%Y/%m/%d %H:%M:%S"))
评论