如何在循环浏览文件名列表时对多个图像进行布莱特?



我正在尝试使用图像文件名上的 for 循环来块状移动汽车的多个图像。但是,它只会绘制屏幕,但实际上不会显示/点亮图像。我正在使用python3.6

。这是我的代码。

import pandas as pd
import pygame
# BLACK = (  0,   0,   0)
# WHITE = (255, 255, 255)
# BLUE =  (  0,   0, 255)
# GREEN = (  0, 255,   0)
# RED =   (255,   0,   0)
df = pd.read_csv('./result.csv')
preds = df['Predicted Angles']
true = df['Actual Angles']
filenames = df['File']
pygame.init()
size = (640, 320)
pygame.display.set_caption("Data viewer")
screen = pygame.display.set_mode(size, pygame.DOUBLEBUF)
myfont = pygame.font.SysFont("monospace", 15)
for i in range(len(list(filenames))):
img = pygame.image.load(filenames.iloc[i])
screen.blit(img, (0, 0))
pygame.display.flip()

查看结果.csv

首先加载所有图像并将它们放入列表或其他数据结构中,然后将当前图像分配给变量并在所需的时间间隔后进行更改(您可以使用这些计时器之一(。

我只是在使用一些彩色的pygame。下面的示例中的曲面,并借助自定义事件和pygame.time.set_timer函数更改当前图像/表面,该函数在指定时间过后将事件添加到事件队列中。

import pygame as pg

pg.init()
screen = pg.display.set_mode((640, 480))
clock = pg.time.Clock()
BG_COLOR = pg.Color('gray12')
images = []
# Three differently colored surfaces for demonstration purposes.
for color in ((0, 100, 200), (200, 100, 50), (100, 200, 0)):
surface = pg.Surface((200, 100))
surface.fill(color)
images.append(surface)
index = 0
image = images[index]
# Define a new event type.
CHANGE_IMAGE_EVENT = pg.USEREVENT + 1
# Add the event to the event queue every 1000 ms.
pg.time.set_timer(CHANGE_IMAGE_EVENT, 1000)
done = False
while not done:
for event in pg.event.get():
if event.type == pg.QUIT:
done = True
elif event.type == CHANGE_IMAGE_EVENT:
# Increment the index, use modulo len(images)
# to keep it in the correct range and change
# the image.
index += 1
index %= len(images)
image = images[index]  # Alternatively load the next image here.
screen.fill(BG_COLOR)
# Blit the current image.
screen.blit(image, (200, 200))
pg.display.flip()
clock.tick(30)
pg.quit()