[英]How do I create a user given amount of images (in PIL - Python)?
I have a problem that should be easy to solve but I can't think of how to do it. 我有一个应该很容易解决的问题,但是我没想到该怎么做。 Here is my code:
这是我的代码:
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))
However, I want to do this (create images and name them) a user given amount of times. 但是,我想给用户指定的时间(创建图像并为其命名)。 How is this possible?
这怎么可能? Full code is here - https://github.com/LouisPi/flashcard_generator/blob/master/main.py
完整代码在这里-https://github.com/LouisPi/flashcard_generator/blob/master/main.py
Use a loop or list comprehension. 使用循环或列表理解。 Something like:
就像是:
images = []
for i in range(num_images):
images.append(Image.new('RGB', (w//2, h//2), (255, 255, 255)))
Or for the comprehension: 或理解:
images = [Image.new('RGB', (w//w, h//w), (255, 255, 255)) for i in range(num_images)]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.