TypeError:' Frame' object不可调用错误

时间:2017-08-24 21:39:29

标签: python-3.x tkinter

我试图编写一个代码,首先从excel文档创建一个数据框,创建一个tkinter窗口和一个基本上是megawidget的窗口内的框架。底部的for循环用于创建megawidget的新实例。

import pandas
from tkinter import *
#assigns a dataframe variable
summer17=pandas.read_excel("summer17.xlsx","list")

window=Tk()#Start of the main window
row_widget = Frame(window)#Creates a frame or "megawidget"
row_widget.grid()
#Variaous variables for widget parameters
tw_height = 1.5
tw_width1 = 30
tw_width2 = 5
brew_row = 14
#Text blocks for megawidget
t1=Text(row_widget,height=tw_height,width=tw_width1)
t1.grid(row=0,column=0)
t1.insert(END,summer17.iloc[brew_row,0])

t2=Text(row_widget,height=tw_height,width=tw_width1)
t2.grid(row=0,column=1)
t2.insert(END,summer17.iloc[brew_row,1])

t3=Text(row_widget,height=tw_height,width=tw_width2)
t3.grid(row=0,column=2)
t3.insert(END,summer17.iloc[brew_row,2])

t4=Text(row_widget,height=tw_height,width=tw_width2)
t4.grid(row=0,column=3)
t4.insert(END,summer17.iloc[brew_row,3])

t5=Text(row_widget,height=tw_height,width=tw_width2)
t5.grid(row=0,column=4)
t5.insert(END,summer17.iloc[brew_row,4])

t6=Text(row_widget,height=tw_height,width=tw_width2)
t6.grid(row=0,column=5)
t6.insert(END,summer17.iloc[brew_row,5])
#for loop to create new instances of the megawidget
for i in range(len(summer17.index)):
    row = row_widget(Frame)
    row.grid(row=i,column=0)

window.mainloop()

然后,我得到了这个错误

追踪(最近一次通话):   文件" dataframe_v1.py",第40行,in     row = row_widget(Frame) TypeError:' Frame'对象不可调用

1 个答案:

答案 0 :(得分:0)

正如上面的评论所指出的,解决这个问题的方法是从for循环中删除for i in range(len(summer17.index)): row = row_widget row.grid(row=i,column=0) 。它现在应该看起来像

{{1}}