Search code examples
pythontkintertreeview

How to make Treeview using python tkinter with just 3 rows. By default treeview is displayed which has many row


I want to make treeview with just three rows, the size of the table should be 3 rows I tried the folowing code

    tv1 = ttk.Treeview(self)
    tv1['columns'] = ('Expiry','Name')
    tv1.heading("#0", text='Symbol', anchor='center')
    tv1.column("#0", anchor="center")
    tv1.heading('Expiry', text='Expiry')
    tv1.column('Expiry', anchor='center', width=100)
    tv1.heading('Name', text='Full Name')
    tv1.column('Name', anchor='center', width=100)
    tv1.grid(row=0,column=12,sticky='n')
    init.treeview1 = tv1
    self.grid_rowconfigure(0, weight = 1)
    self.grid_columnconfigure(0, weight = 1)

Solution

  • Just assign the height as 3

    tv1 = ttk.Treeview(self, height=3)
    

    You should read this simple documentation for further questions of this nature.