__zero__

[Tkinter] Open file dialog

Oct 25th, 2018
280
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.60 KB | None | 0 0
  1. # @author: __zero__
  2.  
  3. from tkinter import *
  4. from tkinter import filedialog, ttk
  5.  
  6.  
  7. def openFile():
  8.     f = filedialog.askopenfilename(
  9.         filetypes=[('Config Files (CFG)', '.cfg'),('All files (*.*)', '.*')]
  10.                                    )
  11.     msg = "Sucess >> %s" % f if len(f) > 0 else "Error"
  12.     path.set(msg)
  13.     print(msg)
  14.  
  15.        
  16. root = Tk()
  17. root.geometry("300x60")
  18. root.resizable(0, 0)
  19. root.title("files..")
  20.  
  21. path = StringVar()
  22.  
  23. Label(text="FILE_PATH$", textvariable=path).pack()
  24. search = ttk.Button(text="Search file", command=lambda: openFile() ).pack()
  25.  
  26. root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment