I want to build an efficient file browser, where my intention is to open up only 4 specific file types, it is happening, but the problem is I want that in the file dialog box, only those file types should appear, so that selection becomes easier, but now what is happening is all the other folders are also appearing, but what i want is in the file dialog box only those files should appear which file types I want to open up. How to do this??
import tkinter as tk
import os
from tkinter import filedialog
window=tk.Tk()
apps=[]
def file_browser():
for widget in frame.winfo_children():
widget.destroy()
filename=filedialog.askopenfilename(initialdir="/",title="Select File",
filetypes=(("presentations","*.pptx"),("Word Files","*.docx"),("All PDFs","*.pdf"),
("All text files","*.txt")))
apps.append(filename)
for app in apps:
label=tk.Label(frame,text=app,bg="yellow",fg="red")
label.pack()
def run_apps():
for app in apps:
os.startfile(app)
window.title("Document Finder")
canvas=tk.Canvas(window,height=500,width=500,bg="#263D42")
canvas.pack()
frame=tk.Frame(window,bg="white")
frame.place(relwidth=0.8,relheight=0.8,relx=0.1,rely=0.1)
btn1=tk.Button(window,text="Open File", padx=10, pady=5,
fg="white",bg="#263D42",command = file_browser)
btn1.pack()
btn2=tk.Button(window,text="Run File", padx=10, pady=5,
fg="white",bg="#263D42",command=run_apps)
btn2.pack()
window.mainloop()