【问题标题】:how to "center text in a row" tkinter treeview如何“将文本居中” tkinter treeview
【发布时间】:2020-10-02 20:30:00
【问题描述】:

我想在行中居中文本。我将 tkinter 用于 GUI。我应该使用哪个代码以及在哪里使用?

tv1["column"]=list(pivot.columns)
tv1["show"] = "headings"
for column in tv1["columns"]:
    tv1.heading(column, text = column)
    
pivot_rows = pivot.to_numpy().tolist()
for row in pivot_rows:
    tv1.insert("","end", values=row)

【问题讨论】:

  • 看看here
  • 我试过这个,它改变了列。我想改变行位置。
  • 尝试tv1.column("#1", anchor="center") 更改第二行,或者您对第二列的任何cid。 (source)

标签: python tkinter treeview


【解决方案1】:
tv1["column"] = list(pivot.columns)
tv1["show"] = "headings"
for column in tv1["columns"]:
    tv1.column(column, anchor=CENTER) # This will center text in rows
    tv1.heading(column, text=column)
    
pivot_rows = pivot.to_numpy().tolist()
for row in pivot_rows:
    tv1.insert("","end", values=row)

发现于documentation

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-04-29
    • 1970-01-01
    • 2021-09-15
    • 2022-01-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多