简体   繁体   English

设置滚动条以使用树状视图

[英]Setting a scrollbar to work with a treeview

I'm attempting to add a scrollbar to a tree here in order to keep the data within view for the user, as the tree stretches offscreen(the window is limited at 1280x720). 我试图在此处向树中添加滚动条,以使数据在用户的视野内,因为树在屏幕外延伸(窗口限制为1280x720)。 However, the scrollbar does not move it across. 但是,滚动条不会将其移动。 Here is the code: 这是代码:

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)

Does anyone know how I would go about restricting the size of the tree in order to get it into a position where it can be scrolled across with in the bounds of the window? 有谁知道我将如何限制树的大小,以便使其进入可以在窗口范围内滚动的位置?

Scrollbars need to be told what command to run when the user moves the scrollbar, and widgets need to know which command to run when it has been scrolled. 当用户移动滚动条时,需要告知滚动条要运行什么命令,而小部件则需要知道滚动后要运行哪个命令。 You're not doing either of these. 您什么都不做。

For example, in your code you need to do both of these: 例如,在您的代码中,您需要执行以下两项操作:

hsb.configure(command=self.tree.xview)
self.tree.configure(xscrollcommand=hsb.set)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM