

:-) But you may find that useful too, as you cobble together a solution. If it were that easy I would have said so earlier This makes it fairly difficult to use to ask the widget *how far* off the Only get a bounding box if the text is currently visible on the screen. This is, however, probably not the answer you are looking for, because you To have by asking it for the geometric position of the last character with
WINFO ASKING IDEAS CODE
Widget, and compared how many lines my code thought the widget should What I did was set up unit test that threw random snippets at the text

On Wed, 12:52:21 -0700, James Stroud wrote:Īh, in that case you want the measure attribute of the font object. UCLA-DOE Institute for Genomics and Proteomics I think I can do this given these limitations. Only one size and am also quite comfortable with giving away several pixelsĪt the end of a line for "rounding errors" and will filter for a limitedĪlphabet consisting only of the numbers, the captial letters, and the space. I am using a fixed width font (courier) only, and My setup is not very complicated, so I don't think I have to worry about The width of the font in points does not correlate with its width in pixelsīased on some simple expriments I have done. How might I query the size of a fixed-width font in pixles? It appears that Use a fixed-width font and manually wrap. On Wednesday 27 April 2005 12:10 pm, so sayeth Jeremy Bowers: 2. and note based on this I can't even guarantee #2īasically, I'm pretty sure you can't do this. Kerning or one of its simpler friends), and it probably changes (probably has something to do with trying to space the letters out, The edge, sometimes if it's one pixel off, damned if I can find a pattern Text, same wrap every time), sometimes it wraps a word if it goes up to The edge cases kill you while Tk is consistent (same I have blown many, many hours on this problem, and I found I would strongly, strongly suggest finding another way to do what you are Of the text widget, even if the widget is being wrapped), so completely Gets into just the right position, it can actually run off the right end I actually found some bugs in the wrapping code (if a Unicode character In the proportional text case, and it *still* doesn't work. I have 70 line function that tries to replicate the Tk wrapping algorithm (It's pretty easy then, youĬan ask the font for how wide any char is and do the math from there.) You can't tell anyhow if you're using a proportional font.Ģ. I have extensive experience with trying to get text containers to do this.ġ. Wrap were turned on, it would be good to know how many characters the Text I am notĪfter the built in "wrap" option, it does not do what I want. I am formatting text dynamically and so I rely on the width. Text to see how many characters it thinks it can display within the container On Wed, 10:52:14 -0700, James Stroud wrote: This is more or less what I would like, but I would also like to probe the

You'll get a Text that will shrink and expand as much as you like. The "trick" is to create the Text as small as possible (width=1, height=1), make it fill its whole container (pack(fill=BOTH, expand=1)), then set the dimensions for the container window (geometry('500x200')). If you want a Text widget to be the smallest as possible in its container, you can do something like:

How do you create your Text widget? Do you specify a width and height? If you do not, the default width and height are 80 and 24 respectively, and the widget won't resize to less than that. This is supposed to be the regular behaviour. I would like for a tkinter text widget to be aware of how big the frame thatĬontains it is, then I would like for it to reset its width to theĪppropriate number of characters when this frame changes size.Įrrr.
