Я долго ломал голову над тем, чтобы найти что-то, что работает, не очень красиво, но оно дает возможность свободно публиковать улучшения, если вы знаете лучший способ. И, возможно, это спасет кого-то от разочарования в качестве отправной точки.
'''
from tkinter import ttk, Button, Entry, Label, Tk, Scrollbar, Frame
root = Tk()
root.geometry("500x300")
my_frame = Frame(root)
my_frame.pack()
# some value's so interperter doesn't freak out
a = 10
b = 30
c = 50
# list representing stuff from database query return
list_data = [(a, b, c, 1), (a, b, c, 2), (a, b, c, 3), (a, b, c, 4),
(a, b, c, 5), (a, b, c, 6), (a, b, c, 7), (a, b, c, 8), (a, b, c, 9),
(a, b, c, 10), (a, b, c, 11), (a, b, c, 12), (a, c, b, 13),
(a, b, c, 14),]
# list to hold column titles
# changed col1 to row id and up to 3 for columns to make it more clear
cols = ["row id", "col1", "col2", "col3"]
tree = ttk.Treeview(my_frame, selectmode="browse")
tree.pack(side="left")
tree["columns"] = cols
tree["show"] = "headings"
for col in range(len(cols)):
tree.column(col, width=100, anchor="c")
tree.heading(col, text=cols[col])
# spaghetti code but it does work as intended
# think the problems came from the list being tuples
# even after converting to list of lists couldn't shift normally
#
# created some lists as placeholders
list1 = []
list_of_lists = []
# converted list off tuples to list of lists
list_of_lists = [list(elem) for elem in list_data]
# looping thru the list to change the order to get last entry first
# did try to do it in a shifting function but couldn't get it to work
for part in list_of_lists:
list1.append(part[-1])
list1.append(part[0])
list1.append(part[1])
list1.append(part[2])
# chopped it into pieces still hardcoded length of 4 in for readability of example
chunk = [list1[x:x+4] for x in range(0, len(list1), 4)]
# back to the original lines but calling chunk instead of list_data
for data in range(len(chunk)):
tree.insert("", "end", text=chunk[data], values=chunk[data])
side_scroller = Scrollbar(my_frame, orient="vertical", command=tree.yview)
side_scroller.pack(side="right", fill="y")
tree.configure(yscrollcommand=side_scroller.set)
root.mainloop()
,,,