Reputation: 1
I have a python tkinter treeview that has a header font size of 12 and an row font size of 8. I have one item in the treeview. In one of the columns (lets say column 3) of the item, i have a text string that is significantly longer than the width of the column. If I use a word wrap function to warp the text string after 90 characters, the text string creates 22 rows of text in the item's column - all at font size 8.
How can I use style, height, and rowheight to set the treeview widget so that the full text in the column is displayed in the treeview and the bottom of the treeview aligns with the bottom of column 3 of the item - so that there's no white space between the bottom of the item and the bottom of the treeview? I've tried using metrics with my font to calculate the linespace and then set rowheight to linespace. But nothing seems to work.
header_font = tkfont.Font(family='TimesNewRoman', size=12)
row_font = tkfont.Font(family='TkFixedFont', size=8)
row_font.metrics()['linespace']
style = ttk.Style()
treeview.height=1
style.configure("Treeview.Heading", font=header_font, rowheight=int(12*2.5))
style.configure("Treeview", font=row_font, rowheight=(row_font.metrics()['linespace']*2.5))
Note: The treeview is in a frame using pack.
Upvotes: 0
Views: 807
Reputation: 1
I can get the text to wordwrap using textwrap.wrap. For one item, this would result in 22 lines of text from the single string. For another item, this may result if 21 lines, etc. Note: I'm only displaying one item at a time in the treeview because of the length of the textstring. And I can set the font using a style to get it displayed in 8 point.
What I can't figure out is how to get the size of the treeview and/or frame to cut off at the bottom of the item/column so that I have no whitespace between the bottom of the item/column and the bottom of the treeview/frame, and the border around the item/columns is the bottom border of the treeview/frame.
If I set rowheight to the number of rows created from the textwrap, sometimes the bottom will cut off before the last row(s) for the item is displayed, sometimes in the middle of the row. And if I try to add a factor to the rowheight, it may be on for one row and off for other column heights.
Note: I will be loading textstrings of different length into the longest column so that's why I need to figure out a formula that will set the bottom of the treeview/frame to be the bottom of the content area/item area/column with the biggest height.
Upvotes: 0