我有一个应该很容易解决的问题,但是我没有想到该怎么做。这是我的代码:
image_1 = Image.new('RGB', (w//2, h//2), (255, 255, 255))
image_2 = Image.new('RGB', (w//2, h//2), (255, 255, 255))
image_3 = Image.new('RGB', (w//2, h//2), (255, 255, 255))
image_4 = Image.new('RGB', (w//2, h//2), (255, 255, 255))
image_5 = Image.new('RGB', (w//2, h//2), (255, 255, 255))
image_6 = Image.new('RGB', (w//2, h//2), (255, 255, 255))
image_7 = Image.new('RGB', (w//2, h//2), (255, 255, 255))
image_8 = Image.new('RGB', (w//2, h//2), (255, 255, 255))
但是,我想给用户指定次数的操作(创建图像并为其命名)。这怎么可能?完整代码在这里-https://github.com/LouisPi/flashcard_generator/blob/master/main.py
答案 0 :(得分:2)
使用循环或列表理解。像这样:
'001'
或者对于理解:
images = []
for i in range(num_images):
images.append(Image.new('RGB', (w//2, h//2), (255, 255, 255)))