#๐Ÿ”’ Is it possible to calculate this?

23 messages ยท Page 1 of 1 (latest)

slim mauveBOT
#

@white beacon

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

worn patio
#

You'd need to know the width of each character.

#

unless it's fixed-width

#

hah, I was just going to suggest PIL.

#

Really the best way is to render it first and measure it.

#

as far as I know

#

it's not a trivial problem fwiw

#

It's a difficult problem to solve. Fonts are very complex.

echo gull
#

But rendering and measuring is probably a viable strategy: but then you may run into os related differences in rendering.

white beacon
#

i personally used pygame for font rendering and checking. pygame has functions that return the width,height of a given text with given font and size without rendering it

echo gull
#

Monospaced fonts make this easier

worn patio
#

@white beacon What is your application doing with the strings? It may be better/easier to just force a certain string length with a good margin.

white beacon
#

with most non-monospace fonts, that would lead into a very ugly result

worn patio
#

fair

#

depends on the application

#

I think it's doing what you are trying to do

#

That site dynamically resizes the text area depending on the length of the input string.

#

(so it fits inside a bounding box)

echo gull
#

Yup, so a crude answer is to just come up with an estimate that errs on the side of caution

slim mauveBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.