2017-04-04 14 views
1

データをテーブルとして返すコードを作成しようとしています。残念ながら、表示するデータポイントが2つしかないのに、12行9列を返します。私のミスはどこですか?Python Tkintertableがウィンドウにあまりにも多くの行/列にフィットする

これは使用されるコードである:

Pastebin with code

import Tkinter as tk 
from tkintertable.Tables import TableCanvas 
class createTable(tk.Frame): 
    def __init__(self, master=None): 
     tk.Frame.__init__(self, master) 
     ######################################### 
     self.master.grid_rowconfigure(0, weight=1) 
     self.master.grid_columnconfigure(0, weight=1) 

     self.grid_rowconfigure(0, weight=1) 
     self.grid_columnconfigure(0, weight=1) 

     self.grid(sticky=tk.NW+tk.SE) 
     ######################################### 
     self.F = tk.Frame(self) 
     self.F.grid(row=0, column=0, sticky=tk.NW+tk.SE) 
     self.createWidgets() 

    def createWidgets(self): 
     self.table = TableCanvas(self.F,cellwidth=250, editable=False,) 
     self.table.createTableFrame() 
     model = self.table.model 
     model.importDict(d) 
     self.table.redrawTable() 

if __name__ == '__main__': 
    f = open("./out.txt") 
    tempDic = {} 

    for var, line in enumerate(f): 
     if not "\t" in line and line != '\n': 
      key = line.replace(":","").strip() 
      tempDic[key] = [] 
     elif line == '\n': 
      continue 
     else: 
      tempDic[key].append(line.replace("\t","").replace(" ","").strip().replace(":","")) 
    f.close() 

    a = 0 
    d = {} 

    #Visualize 
    for i, keys in tempDic.iteritems(): 
     d['rec' + str(a)] = {'System': tempDic[i][0], 'Name': tempDic[i][2], 'Version': tempDic[i][1], 'IP': i} 
     a += 1 
    print d 

    app = createTable() 
    app.master.title('Visual') 
    app.mainloop() 

答えて

1

私はそれを考え出し得た:表が事前定義されたモデルを有し、importDict()関数のみ延びWICH上。それを修正するには、新しいモデルを作成するだけです。

関連する問題