Treeview内部如何创建表格线??
下面的代码里的表格,里面是没有表格线,请问如何创建表格线,并设置行颜色等,谢谢!!from tkinter import ttk
from tkinter import *
root = Tk()
tree = ttk.Treeview(root, columns=('col1','col2','col3'))
tree.column('col1', width=100, anchor='center')
tree.column('col2', width=100, anchor='center')
tree.column('col3', width=100, anchor='center')
tree.heading('col1', text='col1')
tree.heading('col2', text='col2')
tree.heading('col3', text='col3')
def onDBClick(event):
item = tree.selection()
print( "you clicked on ", tree.item(item, "values"))
for i in range(10):
tree.insert('',i,values=('a'+str(i),'b'+str(i),'c'+str(i)))
tree.bind("<Double-1>", onDBClick)
tree.pack()
root.mainloop()
Windows似乎设置不了边框,或非常麻烦。
列名(表头)字体颜色等可以改,行的颜色也可以改。
参考:
https://stackoverflow.com/questions/19749476/3-different-issues-with-ttk-treeviews-in-python
...... 求解答,谢谢
from tkinter import ttk
from tkinter import *
root = Tk()
mystyle = ttk.Style()
# mystyle.theme_use('vista') # alt, clam, default, .. 也尝试了多种不同的主题(依然对行的样式无效)
# mystyle.configure('.', relief = 'flat',borderwidth = 3 )# Windows中 borderwidth参数无效(据Stack Overflow的回答)
mystyle.configure('Custom.Treeview', backgroud='silver', foreground='black', bd=0, font=('Calibri', 11))
mystyle.configure("Custom.Treeview.Heading", font=('Calibri', 13,'bold'))# 表头的字体设置
mystyle.map('Custom.Treeview', background=[('selected', 'green')], foreground=[('selected', 'yellow')])# 设置选中时的背景和前景颜色
# 更复杂的样式设置,需要自己查文档,自己验证,对于"边框"我觉得已经没必要搞了,且Windows系统可能真的不支持。。
tree = ttk.Treeview(root, columns=('col1','col2','col3'),
style="Custom.Treeview") # 应用自定义的样式
tree.column('col1', width=100, anchor='center')
tree.column('col2', width=100, anchor='center')
tree.column('col3', width=100, anchor='center')
tree.heading('col1', text='col1')
tree.heading('col2', text='col2')
tree.heading('col3', text='col3')
def onDBClick(event):
item = tree.selection()
print( "you clicked on ", tree.item(item, "values"))
for i in range(10):
tree.insert('',i,values=('a'+str(i),'b'+str(i),'c'+str(i)))
tree.bind("<Double-1>", onDBClick)
tree.pack()
root.mainloop()
阿奇_o 发表于 2021-8-15 22:46
谢谢!!!
页:
[1]