python - How do I create a file chooser using Tkinter? -
i've been trying create file chooser using tkinter. want make happen when "select file" button pressed. problem, however, automatically opens instead of opening gui , creating file directory window after clicking button. not creating properly?
#creates top button/label select 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()
- it's not technically required, should use standard
self
instead ofthis
. - something
a = button(root).grid()
saves result ofgrid()
a
,a
pointnone
. create , assign widget first, call geometry manager (grid()
, etc.) in separate statement. - a widget's
command
function widget call when requested. let's we've defineddef search_for_foo(): ...
.search_for_foo
function.search_for_foo()
whateversearch_for_foo
programmedreturn
. may number, string, or other object. can class, type, or function. however, in case you'd use ordinarycommand=filedialog.askopenfilename
. if need pass argument widget's callback function, there ways that.
Comments
Post a Comment