我有这个功能:
imagewidth = 250
y_positions = [65.0, 85.0, 105.0, 125.0, 145.0, 165.0]
numbers_to_show = [20, 30, 40, 50, 60, 70]
def draw_numbers(imagewidth, y_positions, numbers_to_show):
counter = 0
while counter < len(y_positions):
numbers_to_show = str(numbers_to_show[counter])
font = ImageFont.truetype("impact.ttf",20)
img = Image.open("agepyramid.bmp")
draw = ImageDraw.Draw(img)
draw.text(20 , y_positions[counter],numbers_to_show,(0,0,0),font=font)
draw = ImageDraw.Draw(img)
img.save("agepyramid.bmp")
counter = counter + 1
我认为这个函数应该在图像的“y_position”给我一张带有“numbers_to_show”的图片,但它给了我这个错误:
draw.text(20 , y_positions[counter],numbers_to_show,(0,0,0),font=font)
TypeError: text() got multiple values for argument 'font'
我做错了什么?
答案 0 :(得分:4)
Draw.text
的第四个参数是font
。您为font
参数提供了2个值 - (0, 0, 0)
(按位置)和font
(按名称),这会使解释器混淆。
我猜你想要
draw.text((20 , y_positions[counter]), numbers_to_show, (0, 0, 0), font=font)
其中(0, 0, 0)
是fill
参数的值。