程序运行后,单击按钮开始读诗.左上角的指针会开始旋转,背景是学生自己画的。
from turtle import Turtle,Screen from time import sleep from winsound import PlaySound,SND_ASYNC,SND_LOOP screen = Screen() screen.delay(0) # 屏幕延时为0毫秒 screen.setup(606,510) screen.bgpic('dflf.png') screen.title('登飞来峰by龚春*、杨予*') #旋转的大箭头 ##绘制大箭头 pointer=((0,0),(25,0),(25,100), (50,100),(0,150),(-50,100), (-25,100),(-25,0)) screen.addshape("bigarrow",pointer) # 注册多边形造型 screen.addshape('按钮.gif') ##旋转箭头 t = Turtle(shape="bigarrow") # 新建海龟对象 t.shapesize(0.1,0.3) # 设定造型的尺寸 t.speed(0) # 速度为最快 t.penup() # 抬笔 t.goto(-240,200) # 坐标定位 t.color('brown') # 设定颜色 def rotate(): t.left(1) screen.ontimer(rotate,50) # 50毫秒后再次调用rotate # 显示歌词段 t2=Turtle(visible=False) # 新建用来写字的海龟 t2.penup() t2.left(90) t2.color('blue') t2.goto(120,-20) f = open('登飞来峰.txt') # 打开文件 c = f.read() # 读取所有歌词 f.close() # 关闭文件 lrc = c.split('\n') # 按钮程序段 b=Turtle(shape='按钮.gif') # 新建开始按钮 b.speed(0) # 速度为最快 b.penup() # 抬笔 def start_sing(x,y): if b.isvisible(): b.hideturtle() rotate() ft=('黑体',14,'normal') for line in lrc: # lrc列表中的每行歌词 t2.write(line,font=ft) # 在屏幕上写line t2.bk(22) # 倒退22个距离 sleep(0.2) PlaySound('登飞来峰.wav',SND_ASYNC|SND_LOOP) b.onclick(start_sing) screen.mainloop()
发表评论