-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathtext2gif.py
49 lines (47 loc) · 1.31 KB
/
text2gif.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# -*- coding: utf-8 -*
#-------------------------------------
# python2.7
# author:loster
# version:0.1
# description:将txt文档中文字以gif界面的方式显示
#------------------------------------
import pygame
from pygame.locals import *
from sys import exit
import time
import codecs
#获得文字
def get_text():
with open('test.txt','r') as fp:
#print fp.read()
return fp.read()
if __name__=='__main__':
text=get_text()
print type(text)
text = text.decode('gbk')
length=len(text) #字符串长度
#print text
print length
sum=0
#初始化pygame
pygame.init()
#创建一个窗口
screen=pygame.display.set_mode((500,500),0,32)
#设置标题
pygame.display.set_caption('loster v0.1')
#设置文字属性
my_font=pygame.font.SysFont('SimHei',64)
while True:
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
exit()
for i in range(length):
print text[i]
text_surface=my_font.render(text[i],True,(0,0,0),(255,255,255))
#绘制文字
screen.blit(text_surface,(200,200))
#暂停1000ms
pygame.time.wait(1000)
#刷新
pygame.display.update()