Tkinter ttk TreeView列标题不可见

时间:2014-09-22 17:52:56

标签: python tkinter treeview

我是学习Tkinter的初学者,想要创建一个包含大列的表。然而,如果n_pixel超过653,则列标题和条目会变得很疯狂。您的建议值得高度赞赏。提前感谢你!! - 破甲

import Tkinter as Tk  
import ttk  

root = Tk.Tk()  

Tk.Grid.columnconfigure(root,0,weight=1)  
Tk.Grid.rowconfigure(root,0,weight=1)  

n_pixel=653  

evt_list_name = [" " for i in range (2*n_pixel+2)]  
evt_list_name[0] ="Time"  

for i,j in map(None,range(0,2*n_pixel,2),range(0,n_pixel)):    
    evt_list_name[i+1]="%i"%(j+1)+"L"    
    evt_list_name[i+2]="%i"%(j+1)+"H"    

evt_list_name[2*n_pixel+1] ="Event Flag"  

evt_col =(evt_list_name)
treeview = ttk.Treeview(root, columns=evt_col, show='headings',height=20)
treeview.column(0,width=70,anchor=Tk.W)
for i in range (2*n_pixel):
    treeview.column(i+1,width=50,anchor=Tk.W)

treeview.column(2*n_pixel+1,width=70,anchor=Tk.W)

for x in range(0,43):
    treeview.insert('','end',values=(x,2*x,2+x,))     

treeview.heading(0, text=evt_col[0])
for i in range (2*n_pixel):
    treeview.heading(i+1,text=evt_col[i+1])
treeview.heading(2*n_pixel+1, text=evt_col[2*n_pixel+1])
treeview.grid(sticky=Tk.W+Tk.E+Tk.N+Tk.S)
vsb = ttk.Scrollbar(root,orient="vertical",command=treeview.yview)
hsb = ttk.Scrollbar(root,orient="horizontal",command=treeview.xview)
treeview.configure(yscrollcommand=vsb.set)
treeview.configure(xscrollcommand=hsb.set)
vsb.grid(column=1,row=0,sticky=Tk.N+Tk.S)
hsb.grid(column=0,row=1,sticky=Tk.W+Tk.E)

root.mainloop()

0 个答案:

没有答案