PIL TypeError:text()对于参数'font'具有多个值

Sve*_*ven 3 python python-imaging-library python-3.x

我有功能:

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
Run Code Online (Sandbox Code Playgroud)

我认为此函数应该给我一张图片,图片的“ 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'
Run Code Online (Sandbox Code Playgroud)

我究竟做错了什么?

vau*_*tah 6

的第四个参数Draw.textfont。您为自font变量提供了2个值- (0, 0, 0)(按位置)和font(按名称),这使解释器感到困惑。

我想你要

draw.text((20 , y_positions[counter]), numbers_to_show, (0, 0, 0), font=font)
Run Code Online (Sandbox Code Playgroud)

参数(0, 0, 0)的值在哪里fill