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()
    

You must log in to read the rest of this article. Please log in or register as a user.