python动态字幕之漂亮的女孩自我介绍一例

"""本程序显示一个动态的文字显示字幕,让女孩进行自我介绍"""

from turtle import Turtle,Screen
from time import sleep

def init_screen(width,height,title,picture):
    """新建屏幕对象,参数说明:
    width:宽度
    height:高度
    title:标题
    picture:背景图(png)
    """
    screen = Screen()
    screen.title(title)
    screen.setup(width,height)
    screen.bgpic(picture)
    screen.delay(0)
    return screen

def make_sprite(image,x,y):
    """显示角色,参数说明:
    image:角色的造型图片,gif
    x,y:坐标
    """
    t = Turtle(visible=False)
    t.penup()
    t.shape(image)
    t.goto(x,y)
    t.showturtle()

def draw_frame(t,startpos,endpos,thickness,color):
    """画框,参数说明:
    t:海龟对象
    startpos:起始坐标
    endpos:结束坐标
    thickness:比触宽度
    color:颜色
    """
    x1,y1 = startpos
    x2,y2 = endpos
    width  = x2 - x1
    height = y1 - y2
    t.setheading(0)
    t.color(color)
    t.pensize(thickness)
    t.goto(startpos)
    t.pendown()
    for i in range(2):        
        t.fd(width)
        t.rt(90)
        t.fd(height)
        t.rt(90)
    t.penup()
    
本文隐藏内容 登陆 后才可以浏览
if __name__ == "__main__": all_sentences = ["Hello,我是女黑客。","我也是绿色和平组织的人","我是一个中国人,我的家在江西萍乡。","我家有武功山,孽龙洞等非著名旅游景点。"] title = "自我介绍_by_李兴球" screen_width,screen_height = 1280,960 back_image = "古风素材--122_.png" sprite_image = "Fate_stay_night.gif" screen = init_screen(screen_width,screen_height,title,back_image) screen.addshape(sprite_image) screen.update() sleep(1) make_sprite(sprite_image,0,0) # 生成人物角色 sleep(1) frame_turtle = Turtle(visible=False) # 画框的海龟对象 frame_turtle.penup() draw_frame(frame_turtle,(-400,-350),(400,-450),8,"green") # 画矩形,从左上角到右下角,8笔触大小,颜色。 write_turtle = Turtle(visible=False) # 在框内写字的海龟对象 write_turtle.penup() write_turtle.color("brown") sleep(1) for sentence in all_sentences: # 遍历每句要说的话 say_sentence(write_turtle,(-300,-420),sentence) sleep(1) write_turtle.clear() screen.mainloop()

本程序显示一个动态的文字显示字幕,让女孩进行自我介绍,用的是海龟画图模块