tkinter text width
Martin Franklin
mfranklin1 at gatwick.westerngeco.slb.com
Wed Apr 27 02:50:19 EDT 2005
James Stroud wrote:
> Hello All,
>
> I would like for a tkinter text widget to be aware of how big the frame that
> contains it is, then I would like for it to reset its width to the
> appropriate number of characters when this frame changes size.
>
> I can get a cget("width") for the text, but this does not dynamically reflect
> the visible width.
>
> One way I can think of is getting the size of the font used in the widget then
> getting the width of the frame with cget then doing the appropriate math and
> configuring the text widget upon resize events.
>
> I'm thinking that there must be a more straightforward way.
>
> Any ideas?
>
> James
>
>
James,
Not sure I understand, do you want the text within the text widget to
wrap or change font so it fits? In any case to get a widgets width you
will need to look at the winfo_* methods for that widget
pydoc Tkinter.Frame
<snip>
| winfo_height(self)
| Return height of this widget.
|
<snip>
| winfo_reqheight(self)
| Return requested height of this widget.
|
| winfo_reqwidth(self)
| Return requested width of this widget.
<snip>
| winfo_width(self)
| Return the width of this widget.
|
If you do want the text to wrap there is the option to do this when you
create the instance of the text widget:-
text = Text(root, wrap = "word") # word, char or none
text.pack()
Cheers
Martin
More information about the Python-list
mailing list