Eric Brunel
2003-06-10 08:31:24 UTC
Hi everybody!
How do I force a text object to be of a required size on a canvas in
Tkinter?
I have a Tkinter.Canvas widget onto which I have drawn a rectangle with
create_rectangle(). Inside this rectangle I want to put a text object, but
also make sure that the text does not overflow the rectangle's borders
(rather, the overflow should be cut off from view). Currently I'm trying
to do this with create_text, but that only accepts coordinates for a point
and not for the bounding box. Any ideas?
Is this what you want?How do I force a text object to be of a required size on a canvas in
Tkinter?
I have a Tkinter.Canvas widget onto which I have drawn a rectangle with
create_rectangle(). Inside this rectangle I want to put a text object, but
also make sure that the text does not overflow the rectangle's borders
(rather, the overflow should be cut off from view). Currently I'm trying
to do this with create_text, but that only accepts coordinates for a point
and not for the bounding box. Any ideas?
---------------------------------
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()
---------------------------------
For all options for the text item in a cnavas, see:
http://dev.scriptics.com/man/tcl8.4/TkCmd/canvas.htm#M152
HTH
--
- Eric Brunel <eric.brunel at pragmadev.com> -
PragmaDev : Real Time Software Development Tools - http://www.pragmadev.com
- Eric Brunel <eric.brunel at pragmadev.com> -
PragmaDev : Real Time Software Development Tools - http://www.pragmadev.com