Python Forum
How to format a list when displaying in a tkinter Listbox
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to format a list when displaying in a tkinter Listbox
#1
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)
Reply
#2
The tab character is \t.
Reply
#3
(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()
Reply
#4
You want to use tkinter.ttk treeview, here's an example: https://pyinmyeye.blogspot.com/2012/07/t...-demo.html
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  PysimpleGUI - listbox with list jamesaarr 2 4,289 Sep-06-2021, 09:52 AM
Last Post: jamesaarr
  [Tkinter] listbox constantly being added to the list. speedev 4 2,418 Jun-08-2021, 08:16 PM
Last Post: speedev
  [Tkinter] list box select event triggers when selecting another listbox Roshan 1 4,368 May-09-2021, 08:27 AM
Last Post: Yoriz
  tkinter| listbox.insert problem Maryan 3 3,504 Sep-29-2020, 05:34 PM
Last Post: Yoriz
  Displaying output in GUI ( Tkinter) Zouloutamtam 7 18,376 Sep-29-2020, 02:08 PM
Last Post: Zouloutamtam
  What units does the width parameter of a tkinter Listbox use? Pedroski55 2 5,560 Jul-04-2020, 08:17 AM
Last Post: deanhystad
  [Tkinter] tkinter listbox problem edoardo5782 5 6,551 Sep-10-2018, 07:10 PM
Last Post: edoardo5782
  Tkinter Listbox tab char issues ashtona 4 4,447 Mar-27-2018, 12:28 PM
Last Post: ashtona
  [Tkinter] THow to search a string in a file and display it in listbox by Tkinter mosavit 2 5,635 Jun-21-2017, 08:02 AM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020