0

我试图在此处向树中添加滚动条,以便将数据保留在用户的视图中,因为树延伸到屏幕外(窗口限制为 1280x720)。但是,滚动条不会移动它。这是代码:

self.treeFrame = ttk.Frame(self)
    self.treeFrame.grid(row = 12,column = 0,columnspan = 1000,rowspan = 100)



    self.tree = ttk.Treeview(self.treeFrame,height = 100, columns = ('name','purchaseprice','previousprices','listingprice','buyingformat','postage','fees','potprofit','offers','viewcount','sold','offertaken','username','dispatch','delivered','returned','relist','feedback'))
    self.tree.heading('#0',text = 'saleID',anchor = 'w')
    self.tree.heading('name',text = "Item Name",anchor = 'w')
    self.tree.heading('purchaseprice',text = "Purchase Price",anchor = 'w')
    self.tree.heading('previousprices',text = "Previous Prices",anchor = 'w')
    self.tree.heading('listingprice',text = "Listing Price", anchor = 'w')
    self.tree.heading('buyingformat',text = "Buying Format",anchor = 'w')
    self.tree.heading('postage',text = "Postage",anchor = 'w')
    self.tree.heading('fees',text = "Fees",anchor = 'w')
    self.tree.heading('potprofit',text = "Potential Profit",anchor = 'w')
    self.tree.heading('offers',text = "Best Offer",anchor = 'w')
    self.tree.heading('viewcount',text = "Viewcount",anchor = 'w')
    self.tree.heading('sold',text = "Sold?",anchor = 'w')
    self.tree.heading('offertaken',text = "Offer Taken?",anchor = 'w')
    self.tree.heading('username',text = "Username",anchor = 'w')
    self.tree.heading('dispatch',text = "Dispatched?",anchor = 'w')
    self.tree.heading('delivered',text = "Delivered?",anchor = 'w')
    self.tree.heading('returned',text = "Returned?",anchor = 'w')
    self.tree.heading('relist',text = "Relisted?",anchor = 'w')
    self.tree.heading('feedback',text = "Feedback",anchor = 'w')

    hsb = ttk.Scrollbar(self,orient = "horizontal")
    self.tree.grid(row = 14,column = 0,sticky ='nsew')
    hsb.grid(row = 11,column = 0,columnspan = 10,sticky = 'ew')
    hsb.config(command = self.tree.xview)

有谁知道我将如何限制树的大小以使其进入可以在窗口范围内滚动的位置?

4

1 回答 1

0

滚动条需要知道当用户移动滚动条时要运行什么命令,小部件需要知道滚动条时要运行哪个命令。你没有做这些。

例如,在您的代码中,您需要执行以下两项操作:

hsb.configure(command=self.tree.xview)
self.tree.configure(xscrollcommand=hsb.set)
于 2018-12-27T17:18:37.253 回答