2017-10-20 2 views
0
class table(Frame): 

def __init__(self, parent,headings=None,data=None): 
    Frame.__init__(self, parent,relief='ridge') 
    self.parent=parent 
    self.headings=headings 
    self.data = data 
    self.CreateUI(self.headings) 
    self.LoadTable(self.data) 


    self.yscrollbar = Scrollbar(self.parent,orient=VERTICAL) 
    self.yscrollbar.grid(row=0,column=1,sticky = (N,S,W,E)) 
    self.yscrollbar.config(command=self.treeview.yview) 
    self.treeview.config(yscrollcommand=self.yscrollbar.set) 

    self.xscrollbar = Scrollbar(self.parent,orient=HORIZONTAL) 
    self.xscrollbar.grid(row=1,column=0,sticky = (N,S,W,E)) 
    self.treeview.config(xscrollcommand=self.xscrollbar.set) 
    self.xscrollbar.config(command=self.treeview.xview) 

    self.grid(row=0,column=0) 
def CreateUI(self,headings): 
    tv = Treeview(self,height=20) 
    if(headings==None): 
     tv['columns'] = ('starttime', 'endtime', 'status') 
    else: 
     tv['columns'] = headings[1:] 
     tv.heading("#0", text=headings[0], anchor='w') 
     tv.column("#0", anchor="w") 
     for i in headings[1:]: 
      tv.heading(i, text=i) 
      tv.column(i, anchor='center') 
    tv.grid(sticky = (N,S,W,E)) 
    self.treeview = tv 

def LoadTable(self,data): 
    if(data==None): 
     for i in range(100): 
      self.treeview.insert('', 'end', text="first", values=('sdfa','asdfasd0','asdfasdf')) 
      self.treeview.insert('', 'end', text="Second", values=('sdfa','asdfasd0','asdfasdf')) 
      self.treeview.insert('', 'end', text="third", values=('sdfa','asdfasd0','asdfasdf')) 
    else: 
     for line in data: 
      self.treeview.insert('', 'end', text=line[0], values=line[1:]) 

위의 코드에서 위의 코드에서 테이블을 만들었으므로 y 축 스크롤이 완벽하게 작동하지만 xscrollbar에서 작업 할 수 있습니다. 친절하게 도와 줘서 고마워. 결과 Treeview (하나 같은 테이블)의 한 이미지를 첨부합니다. screeshot of my tkinter window트리보기에서 가로 스크롤을 사용하는 방법, 여기 테이블을 만들기 위해 트리보기를 사용합니다.

답변

0
def CreateUI(self,headings): 
    tv = Treeview(self,height=20) 
    if(headings==None): 
     tv['columns'] = ('starttime', 'endtime', 'status') 
    else: 
     tv['columns'] = headings[1:] 
     tv.heading("#0", text=headings[0], anchor='w') 
    --> tv.column("#0", anchor="center",width=100,minwidth=100) 
     for i in headings[1:]: 
      tv.heading(i, text=i) 
     --> tv.column(i, anchor='center',width=90,minwidth=100)## 
    tv.pack(expand=Y) 
    self.treeview = tv 

당신이 테이블의 루트 창에 사용하는 형상 관리의 속성을 적용 할 필요가 저를 통해, 시도한 사람들을 위해 당신을 감사하십시오. 트리 뷰의 추가 매개 변수, 즉 최소 너비를 사용했습니다. 너비와 최소 너비에 차이가 있으면이 문제를 해결할 수 있습니다.

0

스크린 샷에 따르면 귀하의 테이블은 루트 창에 의해 제공된 공간이 충분하지 않은 것으로 보입니다. 스크롤 바는 아마도이 아니라 눈에 보이는 테이블이 rightside 절단되어 있기 때문에, 그래서 당신은이 기능에 약간의 편집 도움이

+0

내가 볼이 arent 3 또는 4 이상의 열처럼 보이지 않는 더 많은 열을 감지하지 문제는 이미지의 스크롤 막대 쇼입니다. 보여지지 않은 것이 아닙니다. 수평 스크롤 바는 동작하지 않는 스크롤 바입니다. 경계를 초과하는 진실한 것이 잘 작동하고 있습니다. –

+0

트리 뷰의 가로 크기를 제한하는 방법을 제공 할 수 있습니까? 사실 난 그 문제를 해결할 수 있다고 생각, 난 단지 열 사이징을 찾을 수있는 –

0

가 수평으로 된 colomns를 rezize, 트 리뷰 스크롤 할 수 있습니다 (런타임에, '화면 끄기'오른쪽으로 드래그)를 xscrollbar이 활성화됩니다, 또는 는 생성 후 이벤트를 사용하면 코드에 열을 (더 큰)의 크기를 조정 스크롤 및 트 리뷰는, 이러한 버튼의 누름 (트 리뷰가 작성됩니다 말할 때)로, 다른 '.xview은'아무것도

vsbx = tkinter.Scrollbar(root_search_stock, orient="horizontal") 
vsbx.place(x= 40, y = 550, width = 1000) 


tree = tkinter.ttk.Treeview(root_search_stock,\ 
          columns=column_names,yscrollcommand=vsby.set,xscrollcommand=vsbx.set) 
tree.place(x = 50, y = 300) 


vsbx.config(command = tree.xview) 
관련 문제