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() 

  1. it's not technically required, should use standard self instead of this.
  2. something a = button(root).grid() saves result of grid() a, a point none. create , assign widget first, call geometry manager (grid(), etc.) in separate statement.
  3. a widget's command function widget call when requested. let's we've defined def search_for_foo(): .... search_for_foo function. search_for_foo() whatever search_for_foo programmed return. may number, string, or other object. can class, type, or function. however, in case you'd use ordinary command=filedialog.askopenfilename. if need pass argument widget's callback function, there ways that.

Comments

Popular posts from this blog

PHP DOM loadHTML() method unusual warning -

python - How to create jsonb index using GIN on SQLAlchemy? -

c# - TransactionScope not rolling back although no complete() is called -