# tkinter_filebrowser_test.py # Python Tk GUI based File Browsing and Opening # RJM Programming # April, 2022 import subprocess import getpass import sys from Tkinter import * from tkFileDialog import askopenfilename from tkFileDialog import askopenfilenames def main(): user=getpass.getuser() total=len(sys.argv) # Get the arguments list cmdargs = str(sys.argv) root=Tk() root.title("File Browsing") if total > 1: cmdargs=cmdargs.replace(str(sys.argv[0]) + " ", "") Title_Screen = Label(root, text="File Browsing ->", fg="darkgrey", bg="red", font="Helevetica 25 bold", pady = "20", padx = "20", ).grid(row=3, column=3) filenames = askopenfilenames(initialdir=cmdargs, filetypes=[("allfiles","*"), ("jpgfiles","*.jpg"), ("tiffiles","*.tif*"), ("bmpfiles","*.bmp"), ("pngfiles","*.png"), ("giffiles","*.gif"), ("htmlfiles","*.html"), ("htmfiles","*.htm"), ("pdffiles","*.pdf"), ("phpfiles","*.php"), ("pythonfiles","*.py"), ("perlfiles","*.pl"), ("swiftfiles","*.swift"), ("m4vfiles","*.m4v"), ("m4afiles","*.m4a"), ("wavfiles","*.wav"), ("mp4files","*.mp4"), ("docfiles","*.doc*"), ("xlsfiles","*.xls*"), ("txtfiles","*.txt")]) for filename in filenames: if '.php' in filename: p = subprocess.Popen('/usr/bin/php ' + filename, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) elif '.py' in filename: p = subprocess.Popen('/usr/bin/python ' + filename, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) elif '.pl' in filename: p = subprocess.Popen('/usr/bin/perl ' + filename, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) else: p = subprocess.Popen('open file://' + filename, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) for line in p.stdout.readlines(): print line, retval = p.wait() main()