Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
TreeView column headers
#1
Hello all
I have posted a code section of a larger program where im trying to populate a a treeview with 2 columns and inset 2 values.
My issue is the treeview will show but the 2 column headers will not display as well as the 2 values.
thank you for any direction

# Introduction to Python Programming
from tkinter import *
import shelve
from tkinter import ttk
class MyFrame (Frame):
    def __init__(self):
        Frame.__init__(self)
        self.master.geometry("600x600")
        self.master.title("Student Scores")
        self.grid()
           
        #Create and define a TreeView
        columns = ("student", "score")
        self.treeview = ttk.Treeview(self, columns = columns, show = "headings")
        self.treeview.column("student",anchor=CENTER, stretch=NO, width=20)
        self.treeview.heading("student", text="Student")
        self.treeview.column("score",anchor=CENTER, stretch=NO, width=20)
        self.treeview.heading("score", text="Score")
        self.treeview = ttk.Treeview(self, height = 15)
        self.treeview.grid(padx = 50, pady = 50)
        #insert values to column
        self.treeview.insert('', 'end', text="Student", values=('Jon', '99'))
        
asn_frame = MyFrame()
asn_frame.mainloop()
Reply
#2
I've uploaded a bare bones basics of all you need to do to create a treeview. I hope it helps.
import tkinter as tk
from tkinter import ttk

root = tk.Tk()
root.title('Student Scores')
root.geometry('600x600')
cols = ("student", "score")
treeview = ttk.Treeview(root, columns = cols, show="headings")
treeview.heading ('student', text='Student')
treeview.heading ('score', text="Scores")
treeview.insert ('', tk.END, values = ('Micky Mouse', '100'))
treeview.insert ('', tk.END, values = ('Bugs Bunny', '81'))
treeview.grid (row=0, column=1)
root.mainloop ()
Reply
#3
Thank you this was very helpful. I have one tweak I would like to make, this code will open up a 2nd window on which contains the TreeView, I would like the view to launch on the primary window where I would have all the other controls
thanks
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to store columns of a .csv in variables (when the .csv has no headers) ? hobbyist 6 1,149 Aug-18-2023, 02:06 PM
Last Post: deanhystad
  export sql table to csv using BCP with headers mg24 0 684 Jan-19-2023, 05:36 AM
Last Post: mg24
  Code changing rder of headers Led_Zeppelin 0 891 Jul-13-2022, 05:38 PM
Last Post: Led_Zeppelin
  Request Headers (scheme) JohnnyCoffee 0 1,889 Mar-31-2021, 09:17 PM
Last Post: JohnnyCoffee
  Reading csv with multiple "headers" Clives 3 2,446 Dec-31-2020, 09:25 AM
Last Post: Ana_junior
  Code snippets for building multi column Listviews and or Treeview KevinBrown 3 3,276 Apr-14-2019, 06:50 PM
Last Post: Yoriz

Forum Jump:

User Panel Messages

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