python - PIL 类型错误 : text() has multiple values for argument 'font'

标签 python python-3.x python-imaging-library

我有这个功能:

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'

我做错了什么?

最佳答案

Draw.text 的第 4 个参数是字体。您为 font 参数提供了 2 个值 - (0, 0, 0) (按位置)和 font (按名称),这会造成混淆口译员。

我猜你想

draw.text((20 , y_positions[counter]), numbers_to_show, (0, 0, 0), font=font)

其中 (0, 0, 0)fill 参数的值。

关于python - PIL 类型错误 : text() has multiple values for argument 'font' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28349169/

相关文章:

python - 在 WebDriverWait 中使用自己的变量。 Selenium 。 Python

python - Virtualenvwrapper.sh 函数在 bash shell 中不可用

python - 当 pip install 'pyrebase' 时,出现错误 ' UnicodeDecodeError: ' cp94 9' codec can' t 在位置 500 : illegal multibyte sequence' 中解码字节 0xe2

python - 警告 : pip is configured with locations that require TLS/SSL, 但是 Python 中的 ssl 模块不可用

python - _imaging C 模块未安装(在 Windows 上)

python - 如何定义两个图像是否相似?

python - Pandas - 取 N 个以前的值并从 Series 中创建矩阵

python - 如果没有数据,尝试使用 bs4 跳过属性

Python 正则表达式与年月组合不匹配

python - 将RGB图像转换为黑白PIL手部识别