You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何设置ttkbootstrap.tableview.Tableview的数据行高度?

解决ttkbootstrap Tableview数据行高度无法修改的问题

你遇到的问题根源在于:ttkbootstrap的Tableview组件内部的Treeview控件使用的是自定义样式名Tableview.Treeview,而非默认的Treeview样式,所以直接配置Treeview的rowheight不会作用到数据行上。

修改后的代码如下:

import ttkbootstrap as ttk
from ttkbootstrap.tableview import Tableview
from ttkbootstrap.constants import *

app = ttk.Window()
style = app.style
# 配置表头样式
style.configure('Treeview.Heading', rowheight=80, font=(None, 18))
# 配置Tableview数据行的样式,注意样式名是Tableview.Treeview
style.configure('Tableview.Treeview', rowheight=80, font=(None, 18))

coldata = [{"text": "LNum", "stretch": False}, "CompanyName", {"text": "UserCount", "stretch": False}]
rowdata = [('A123', 'IzzyCo', 12), ('A136', 'Kimdee Inc.', 45), ('A158', 'Farmadding Co.', 36)]

dt = Tableview(
    master=app,
    coldata=coldata,
    rowdata=rowdata,
    paginated=True,
    searchable=True
)
dt.pack(fill=BOTH, expand=YES, padx=10, pady=10)
dt.load_table_data()
app.mainloop()

关键说明

  • 表头样式依然使用Treeview.Heading,因为Tableview的表头复用了默认的表头样式
  • 数据行必须针对Tableview.Treeview样式配置rowheight和字体,才能生效

内容的提问来源于stack exchange,提问作者Daba

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.03 14:22:37