我是一个初学者,目前正在进行一个个人项目,使用Tkinter在Python2上开发一个小型应用程序。但是,我在调用我创建的函数时遇到了问题。 1。知道Python上的Tkinter是基于事件的,因此我创建了一个按钮来上传一个特定的文件,然后将文件中的值存储到一个列表变量中。 2。之后,我使用另一个按钮尝试调用print函数来打印List变量中存储的值中的值。你知道吗
希望有人能帮我。你知道吗
def uploadFile():
openFile = tkFileDialog.askopenfilename(filetypes = (("",".csv"),("All
files", "*.*")))
with open(openFile) as file:
reader = csv.reader(file)
xUF = [row for row in reader]
return xUF
def printUF():
for row in xUF:
print row
count=0
if count>5:
break
count += 1
def main():
l1=tk.Label(root,text="Upload File")
l1.pack()
l1.place(x=55,y=170)
#buttons/placements for GUI
b1=tk.Button(root,text="Browse", command=uploadFile)
b1.pack()
b1.place(x=100,y=200)
b2=tk.Button(root,text="Print", command=printUF())
b2.pack()
root.title("HELLO")
root.geometry("500x500")
root.mainloop()
if __name__ == '__main__':
main()
我不太清楚你的错误是什么。但我怀疑是这样的:
当我认为您只需要
command=printUF
时,您正在将command=printUF()
传递给Button
类,因为Button
可能希望在函数被命中时调用它。现在,您正在将printUF
的结果而不是函数本身传递给Button
。线条应如下所示:第行缺少括号
相关问题 更多 >
编程相关推荐