为什么树视图窗口小部件虽然只给了两列,但为什么还要增加一列呢?我也无法控制它的宽度

发布于 2021-01-29 15:02:45

  1. 我不知道如何控制小部件的宽度
  2. 我不能只显示2列
    from Tkinter import *
    

    from ttk import Treeview
    root = Tk()
    tree = Treeview(root, height = 10, columns = 2)
    tree[‘columns’] = (‘one’,’two’)
    tree.column(‘one’, width = 50)
    tree.column(‘two’, width = 50)
    tree.heading(‘one’, text = ‘UserName’, anchor = ‘center’)
    tree.heading(‘two’, text = ‘ID’, anchor = ‘centeenter code herer’)
    tree.grid(row = 3, column = 0)
    root.mainloop()

关注者
0
被浏览
100
1 个回答
  • 面试哥
    面试哥 2021-01-29
    为面试而生,有面试问题,就找面试哥。

    第一列是树。您可以使用show属性将其关闭。该值必须是零个或多个值的列表。有效值headings将显示列标题并tree显示树。默认值为['tree', 'headings']

    这是使树视图显示列标题而不显示树的方法:

    tree = Treeview(root, height=10, columns=2, show=["headings"])
    

    如果您想看树,但是想要控制它的宽度,也可以这样做。树列始终可以用标识'#0'。您可以使用该column方法设置宽度:

    tree.column('#0', width=50)
    


知识点
面圈网VIP题库

面圈网VIP题库全新上线,海量真题题库资源。 90大类考试,超10万份考试真题开放下载啦

去下载看看