我无法将字符串“插入”到我的tkinter列表框中。我的代码是:from Tkinter import *
from tkFileDialog import askopenfilenames
def ImportFiles():
Tk().withdraw()
filenames = askopenfilenames()
for f in filenames:
listbox1.insert(END, f)
return
root = Tk()
root.geometry("500x800")
listbox1 = Listbox(root).grid(row=1, sticky=W, padx=20, pady=20)
button1 = Button(root, text='Import', command=ImportFiles).grid(row=2, sticky=W, padx=20)
root.mainloop()
当我运行这段代码时,GUI会很好地弹出。我按下按钮,打开文件对话框,如预期的那样。然后当我选择一些文件并按“确定”时,代码炸弹。我得到以下错误:
文件“C:\Python27\lib\lib tk\特金特.py“,第1536行,in调用
返回自我功能(*参数)
ImportFiles中的文件“../pyGUI_01.py”,第10行
listbox1.insert(结束,f)
AttributeError:“NoneType”对象没有属性“insert”
我不明白。我将对象“listbox1”设置为TK列表框。在我的IDE中没有指示“insert”命令无效(PyCharm)。我做错什么了?在