Setting allowed size of text object on canvas in Tkinter

Mickel Grönroos mickel at csc.fi
Tue Jun 10 05:19:59 EDT 2003


On Tue, 10 Jun 2003, Eric Brunel wrote:

> Mickel Grönroos wrote:
> > Hi everybody!
> >
> > How do I force a text object to be of a required size on a canvas in
> > Tkinter?
> >
> > [...]
>
> Is this what you want?
>
> ---------------------------------
> from Tkinter import *
>
> root = Tk()
> c = Canvas(root)
> c.pack()
> c.create_text(100, 100, text='spam spam spam spam spam', width=75)
> root.mainloop()
> ---------------------------------

No, the text is still wrapping. I would like to be able to se a "height"
option too, so that only the text that fits in the area defined by "width"
and "height" would be visible (and the rest simply not shown at all). Do
you know how to ackomplish that?

(Currently, I use bbox() to get the coordinates of the rectangle and the
text, then I chop of characters from the end of my string in a loop until
the bbox of the text is fully overlapped by the rectangle -- ugly and
possibly slow.)

/Mickel

--
Mickel Grönroos, application specialist, linguistics, Research support, CSC
PL 405 (Tekniikantie 15 a D), 02101 Espoo, Finland, phone +358-9-4572237
CSC is the Finnish IT center for science, www.csc.fi






More information about the Python-list mailing list