Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 14389

ttk.Treeview - how to get multi-line columns

$
0
0

I'm trying to implement a multi-line column within a tkinter treeview. In the below example, I'd like the text in the Description column to wrap across multiple lines. If the user drags the column borders to adjust its size, the text should wrap accordingly. Is this possible? Thanks!

Example

The code for the above example is shown below -

from tkinter import ttkif __name__ == "__main__":    root = tk.Tk()    root.title("TreeView Example")    tree = ttk.Treeview(root, columns=('Category', 'Product ID', 'Description', 'Quantity'))    tree.heading('#0', text='')    tree.heading('Category', anchor=tk.W, text='Category')    tree.heading('Product ID', anchor=tk.W, text='Product ID')    tree.heading('Description', anchor=tk.W, text='Description')    tree.heading('Quantity', text='Quantity')    tree.column('Quantity', anchor=tk.CENTER)    tree.insert('', 'end', "Level 1", text="Level 1")    tree.insert("Level 1", 'end', "Level 2", text="Level 2")    tree.insert("Level 2", 'end', "Level 3", text="Level 3")    tree.insert("Level 3", 'end', "line-1", text="")    tree.set("line-1", 'Category', "CatA")    tree.set("line-1", 'Product ID', "ProdA")    tree.set("line-1", 'Description', "The quick brown fox jumped over the lazy dog. The quick brown fox " +"jumped over the lazy dog. The quick brown fox jumped over the lazy dog. The quick brown fox " +"jumped over the lazy dog. The quick brown fox jumped over the lazy dog. The quick brown fox " +"jumped over the lazy dog. The end")    tree.set("line-1", 'Quantity', "1")    tree.pack(expand=True, fill='both')    root.mainloop()

Viewing all articles
Browse latest Browse all 14389

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>