【发布时间】:2015-09-04 19:05:31
【问题描述】:
我一直在尝试使用 Tkinter 创建文件选择器。我想在按下“选择文件”按钮时实现它。然而,问题是它会自动打开而不是打开 GUI,然后在单击按钮后创建文件目录窗口。我没有正确创建它吗?
#Creates the Top button/label to select the file
this.l5 = Label(this.root,text = "Boxes File:").grid(row = 0, column = 0)
this.filename = StringVar()
this.e3 = Entry(this.root,textvariable = this.filename)
this.button3 = Button(this.root,text = "Select File",command=filedialog.askopenfilename()).grid(row = 0, column = 7)
mainloop()
【问题讨论】:
-
不要把
()放在askopenfilename之后。 -
另外,不要链接
.grid(),否则您最终会将None保存到this.button3。此外,我建议坚持使用标准self而不是使用this。 -
好吧,好像已经解决了。谢谢!
标签: python user-interface button tkinter filechooser