Measuring string width in Python -
i have font (times new roman, 14) , need measure string width. found matplotlib , example api:
from matplotlib import rcparams import os.path afm_filename = os.path.join(rcparams['datapath'], 'fonts', 'afm', 'ptmr8a.afm') matplotlib.afm import afm afm = afm(open(afm_filename)) afm.string_width_height('what heck?')
but can't understand should paste instead of "datapaths", "fonts", "afm". way sting width in python? maybe way?
import tkinter tkinter tkinter import font tkfont tkinter.frame().destroy() txt = tkfont.font(family="times new roman", size=14) width = txt.measure("what heck?") print(width)
Comments
Post a Comment