我想在TreeView中显示500多个条目。以下是我编写的代码:
import tkinter.ttk as ttk
from tkinter import *
#entries is a list of lists containing the data I want to display
master = Tk()
tree = ttk.Treeview(master, columns=('Name', 'Quiz 1', 'Quiz 2', 'MidSem'))
tree.heading('#0', text='ID')
tree.heading('#1', text='Name')
tree.heading('#2', text='Quiz 1')
tree.heading('#3', text='Quiz 2 ')
tree.heading('#4', text='MidSem')
tree.column('#1', stretch=YES)
tree.column('#2', stretch=YES)
tree.column('#3', stretch=YES)
tree.column('#4', stretch=YES)
tree.column('#0', stretch=YES)
tree.pack(fill=BOTH)
for entry in entries:
tree.insert('', 'end', text=entry[0], values=(entry[1], entry[2], entry[3], entry[4]))
当我运行此代码时,即使我调整窗口大小并且我希望看到10行以上的数据,似乎也只能看到10行的数据。 如何增加显示的行数?
答案 0 :(得分:0)
您必须设置expand = 1
import tkinter.ttk as ttk
from tkinter import *
#entries is a list of lists containing the data I want to display
entries = []
for i in range(0,500):
args = (i,'Name','Quiz 1', 'Quiz 2', 'MidSem')
entries.append(args)
master = Tk()
tree = ttk.Treeview(master, columns=('Name', 'Quiz 1', 'Quiz 2', 'MidSem'))
tree.heading('#0', text='ID')
tree.heading('#1', text='Name')
tree.heading('#2', text='Quiz 1')
tree.heading('#3', text='Quiz 2 ')
tree.heading('#4', text='MidSem')
tree.column('#1', stretch=YES)
tree.column('#2', stretch=YES)
tree.column('#3', stretch=YES)
tree.column('#4', stretch=YES)
tree.column('#0', stretch=YES)
tree.pack(fill=BOTH,expand=1)
for entry in entries:
tree.insert('', 'end', text=entry[0], values=(entry[1], entry[2], entry[3], entry[4]))