Malcolm Malcolm - 1 year ago 98
Python Question

Python/Tkinter: Version of Canvas create_text() that supports word wrap

Is there a create_text() mode or technique that supports word wrap? I'm stuck using create_text() vs. a Label or Text widget because I'm placing text on top of an image on my Canvas.

Also, is there a Tkinter API that truncates text that doesn't fit a certain width with an ellipsis like suffix, eg. "Where very, very, very long text" gets converted to something like "Where very, very, ...".

Thank you,

Answer Source

There is indeed a word wrap feature in create_text(). You'd call it like so:

canvas.create_text(x, y, width=80)

You can set the width parameter to whatever max length you want, or 0 if you want no word wrapping. See this article for all the options, arguments etc. for create_text().

I'm not sure about truncating text, but I did see this talking about a way to limit the length of input in an Entry widget...

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download