I'm building a generic, data-driven Tkinter form. Each row has a label on the left and an input field on the right. With simple test data, it works to use a Label for the label text -- but when the desired label text is longer than the Label field, it simply truncates.
Once the form has been built, I won't need to vary the label text dynamically: the text will be known at construction time. But I don't know the universe of possible label strings. I want the form to accommodate longer label text by word-wrapping the label to multiple lines, expanding vertically. This should of course expand the row in which the label is embedded.
Per Create resizable/multiline Tkinter/ttk Labels with word wrap, I presume I should use a Text widget for word wrapping and disable it as an input field. But I don't know how to constrain it horizontally (to engage the word wrapping) while expanding it to exact size vertically.
In other words, the processing sequence should go something like this:
grid_columnconfigure(weight=)
, but am happy to entertain suggestions.)This may have a straightforward answer that would become apparent once I better understand the workings of Tkinter geometry managers in general and Grid in particular. I've read http://effbot.org/tkinterbook/grid.htm and http://effbot.org/tkinterbook/pack.htm without yet having a big "Aha!" moment. I'd be grateful for reference material that addresses this kind of issue as well.
Thanks for any help!
You are looking for the Message
widget:
The Message widget is a variant of the Label, designed to display multiline messages. The message widget can wrap text, and adjust its width to maintain a given aspect ratio.
If you want fancy things like multiple fonts, you'll need to move to a Text
widget. If you just want a longer version of a Label
, though, Message
is a good choice.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With