1

Am trying to use treeview to display results from my database. I tested treeview in a different file and it works fine but when i try to display my database results it cuts off weird.

# Works
Tree = ttk.Treeview(columns = Fields, show = "headings")
Tree.grid(in_ = self.Canvas)

# This piece of code does work
for Column in Fields:
    Tree.heading(Column, text = Column.title())

# Instead of cutting at each item it cuts whenever it sees a space
for Item in Results:
    print(Item)
    Tree.insert('', 'end', values = Item)

Instead of each item in results it cuts off whenever it finds a space. Also when it does display the results you still see the ('text,...')

('87 Xbox Ville', 'Soham', '09458934873', 'Test3@Joshua.com')
('78 Test Town', 'Essex', '07903489451', 'Test2@Nixon.co.uk')
('58 Play Row', 'Soham', '07907849327', 'Test@Nixon.com')

These are the tuples i have (pulled from database) they work if they have zero spaces in but the address line 1 messes it up.

Please help

EDIT I printed out results and copied the output and set it as a variable and it works :/ I cant use the results?

Joshua Nixon
  • 1,379
  • 2
  • 12
  • 25

1 Answers1

0

Check This link out. It has to do with Treeview taking an iterable for each column. The explanation is in the first answer under 'Third Question : the truncature' in bold.

Edit:

If i[3] had multiple words:

    for i in Results:
        print(i)
        temp = i[3]
        tree.insert("", "end", values=((i[0]), (i[1]), temp))
Community
  • 1
  • 1
  • Just read this. I don't fully understand what the iid =. Could you explain? – Joshua Nixon Oct 25 '16 at 16:23
  • iid is just the identifier. You can specify it yourself or let tkinter do it. It is an identifier for the row. so say you enter ['John', 'Brown'] as data into the first row of your table. tkinter would give it an iid, say 1. Using this iid you can do operations like finding out which row is clicked and getting the data. – B3Caballero Oct 25 '16 at 16:38
  • You can just ignore the iid part, tkinter will automatically allocate one to your table. That is until you need to access this data. – B3Caballero Oct 25 '16 at 16:40
  • It now puts all of the fields in one column. I just copied code from one file to this work which works but has the same outcome even though it works in another one i have for testing purposes. The code is basically identical so i have no idea why it doesn't want to work :( very frustrating – Joshua Nixon Oct 25 '16 at 16:44
  • 1
    If you want them in separate columns have you tried placing them doing something like: Item[0], Item[1], etc. ? – B3Caballero Oct 25 '16 at 16:59
  • I have just taken all the unneeded code and just have the raw stuff and it works fine now :/ I don't know why it doesnt when i put everything back – Joshua Nixon Oct 25 '16 at 17:02
  • https://github.com/nixonjoshua98/test_code.git Although you won't be able to see the broken one work without tweaking it you can at least see the code. Any help is appropriated – Joshua Nixon Oct 25 '16 at 17:03
  • Idk about going through all your code, but heres something that worked for me: for i in Results: print(i) temp = i[3] print(temp) tree.insert("", "end", values=((i[0]), (i[1]), temp)) – B3Caballero Oct 25 '16 at 19:17