Python 巨蟒倒数
我目前从网上截取了一段视频,允许用相机拍摄4张照片。这很有效 然后我试着从网络上截取另一个片段,在它拍照之前倒计时,这让我非常头疼,我想知道是否有更聪明的人能帮我把这个弄出来Python 巨蟒倒数,python,pygame,pygame-surface,Python,Pygame,Pygame Surface,我目前从网上截取了一段视频,允许用相机拍摄4张照片。这很有效 然后我试着从网络上截取另一个片段,在它拍照之前倒计时,这让我非常头疼,我想知道是否有更聪明的人能帮我把这个弄出来 surface = pygame.display.set_mode((0,0)) fontObj = pygame.font.Font("freesansbold.ttf", 100) textSurfaceObj = fontObj.render("3", True, (255, 0, 0)) textRectObj =
surface = pygame.display.set_mode((0,0))
fontObj = pygame.font.Font("freesansbold.ttf", 100)
textSurfaceObj = fontObj.render("3", True, (255, 0, 0))
textRectObj = textSurfaceObj.get_rect()
textRectObj.center = (surface.get_width() / 2, surface.get_height() / 2)
def show_image(image_path):
screen = init_pygame()
img=pygame.image.load(image_path)
img = pygame.transform.scale(img,(transform_x,transfrom_y))
screen.blit(img,(offset_x,offset_y))
pygame.display.flip()
def init_pygame():
pygame.init()
size = (pygame.display.Info().current_w, pygame.display.Info().current_h)
pygame.display.set_caption('Pictures')
pygame.mouse.set_visible(False) #hide the mouse cursor
return pygame.display.set_mode(size, pygame.FULLSCREEN)
print "Taking pics"
now = time.strftime("%Y-%m-%d-%H:%M:%S")
try:
for i, filename in enumerate(camera.capture_continuous(config.file_path + now + '-' + '{counter:02d}.jpg')):
print(filename)
for y in range(3,0,-1):
surface.fill((0,0,0,0))
textSurfaceObj = fontObj.render(str(y), True, (255, 0, 0))
surface.blit(textSurfaceObj, textRectObj)
pygame.display.update()
pygame.time.wait(1000)
sleep(capture_delay)
if i == total_pics-1:
break
finally:
camera.stop_preview()
camera.close()
它返回给我这个:
Traceback (most recent call last):
File "pics.py", line 58, in <module>
fontObj = pygame.font.Font("freesansbold.ttf", 100)
pygame.error: font not initialized
回溯(最近一次呼叫最后一次):
文件“pics.py”,第58行,在
fontObj=pygame.font.font(“freesansbold.ttf”,100)
pygame.error:字体未初始化
我的印象是,如果pygame.init()完成,字体应该初始化?这是因为您调用:
pygame.font.Font("freesansbold.ttf", 100)
打电话之前:
pygame.init()
可能在您的文件pics.py的第58行。您已经自己提供了问题的答案。你可能比你想象的要聪明。你试过调用
pygame.font.init()
?在你尝试使用font.font之前,你既没有调用pygame.init()
也没有调用pygame.font.init()
。你会惊讶于你能变得多么聪明;-)