Roughly approximate the width of a string of text in Python?

前端 未结 3 708
误落风尘
误落风尘 2021-01-12 16:34

How would one, using Python, approximate the font width of a given string of text?

I am looking for a function with a prototype similar to:

def getA         


        
3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-12 16:53

    You could render an image with the text using PIL and then determine the resulting image width.

    http://effbot.org/imagingbook/imagefont.htm

提交回复
热议问题