【问题标题】:Why no scroll bars on Table?为什么 Table 上没有滚动条?
【发布时间】:2021-12-20 05:45:26
【问题描述】:

我正在尝试在桌面上添加滚动条,但无论我如何尝试,它们都不会出现。这是我目前所拥有的:

'''

# Table Frame
tree_frame = Frame(root, bg="#ecf0f1")
tree_frame.place(x=0, y=380, width=1980, height=520)
style = ttk.Style()
style.configure("mystyle.Treeview", font=('Calibri', 18),
                rowheight=50)  # Modify the font of the body
style.configure("mystyle.Treeview.Heading", font=('Calibri', 18))  # Modify the font of the headings
tv = ttk.Treeview(tree_frame, columns=(1, 2, 3, 4, 5, 6), style="mystyle.Treeview")


#scrollbar
tree_scroll = Scrollbar(tree_frame)
tree_scroll.pack(side=RIGHT, fill=Y)

tree_scroll = Scrollbar(tree_frame,orient='horizontal')
tree_scroll.pack(side= BOTTOM,fill=X)

my_tree = ttk.Treeview(tree_frame,yscrollcommand=tree_scroll.set, xscrollcommand =tree_scroll.set)


tv.column("# 1",anchor=W, stretch=NO, width=100)
tv.heading("# 1", text="ID")
tv.column("# 2", anchor=W, stretch=NO)
tv.heading("# 2", text="Catagory")
tv.column("# 3", anchor=W, stretch=NO, width=150)
tv.heading("# 3", text="Brand")
tv.column("# 4", anchor=W, stretch=NO, width=255)
tv.heading("# 4", text="Model")
tv.column("# 5", anchor=W, stretch=NO, width=375)
tv.heading("# 5", text="Serial#")
tv.column("# 6", anchor=W, stretch=NO)
tv.heading("# 6", text="Notes")

tv['show'] = 'headings'
tv.bind("<ButtonRelease-1>", getData)
tv.pack(fill=X)

''' 谁有想法?这是我的输出:

【问题讨论】:

    标签: python mysql database tkinter scrollbar


    【解决方案1】:

    滚动条在那里。问题是您在tree_frame 上使用place,这会阻止窗口调整大小以适应小部件。如果您手动使窗口足够大,滚动条就会变得可见。

    如果您使用 packgrid 和适当的选项,窗口将自动调整大小以使所有小部件可见。

    tree_frame.pack(side="top", fill="both", expand=True)
    

    【讨论】:

      猜你喜欢
      • 2012-12-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-04-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多