Python Forum
How to format a list when displaying in a tkinter Listbox - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: GUI (https://python-forum.io/forum-10.html)
+--- Thread: How to format a list when displaying in a tkinter Listbox (/thread-9336.html)



How to format a list when displaying in a tkinter Listbox - nortski - Apr-02-2018

I have a list that has 3 columns. How can I insert a tab to space out the columns while displaying the rows in a tkinter listbox.
I insert the the with:

for item in myList:
    listbox.insert(END, item)

I've done a little digging and can space them out using .format(), how can I change this code to use tabs instead?

for row in range(len(myList)):
    item = "{:<25s}{:>6s}".format(myList[row][0],myList[row][1])
    print(item)
    listbox.insert(END, item)



RE: How to format a list when displaying in a tkinter Listbox - nilamo - Apr-02-2018

The tab character is \t.


RE: How to format a list when displaying in a tkinter Listbox - nortski - Apr-03-2018

(Apr-02-2018, 05:19 PM)nilamo Wrote: The tab character is \t.
Yes but that doesn't appear to be valid systax to use with .format()


RE: How to format a list when displaying in a tkinter Listbox - Larz60+ - Apr-03-2018

You want to use tkinter.ttk treeview, here's an example: https://pyinmyeye.blogspot.com/2012/07/tkinter-multi-column-list-demo.html