Advertisement
Guest User

file explorer in python

a guest
Jan 26th, 2020
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.38 KB | None | 0 0
  1. import tkinter as tk
  2. from tkinter import filedialog, Text
  3. import os
  4.  
  5. root = tk.Tk()
  6. apps = []
  7.  
  8. if os.path.isfile('save.txt'):
  9.     with open('save.txt', 'r') as f:
  10.         tempApps = f.read()
  11.         tempApps = tempApps.split(',')
  12.         apps= [x for x in tempApps if x.strip()]
  13.        
  14. def addApp():
  15.     for widget in frame.winfo_children():
  16.         widget.destroy()
  17.    
  18.     filename = filedialog.askopenfilename(initialdir="~/MEGA",title="Select File",
  19.     filetypes=(("executables","*.exe"), ("all files",
  20.     "*.*")))
  21.     apps.append(filename)
  22.     print(filename)
  23.    
  24.     for app in apps:
  25.         label = tk.Label(frame, text=app, bg="grey")
  26.         label.pack()
  27.  
  28. def runApps():
  29.     for app in apps:
  30.         os.startfile(app)
  31.        
  32. canvas = tk.Canvas(root, height=600, width=600, bg="#263D42")
  33. canvas.pack()
  34.  
  35. frame =tk.Frame(root, bg="white")
  36. frame.place(relwidth=.8, relheight=.8, relx=.1, rely=.1)
  37.  
  38. openFile = tk.Button(root, text="Open File", padx=10, pady=5,
  39.                      fg="white", bg="#263D42", command=addApp)
  40. openFile.pack()
  41.  
  42. runApps = tk.Button(root, text="Run App", padx=10, pady=5,
  43.                      fg="white", bg="#263D42", command=runApps)
  44. runApps.pack()
  45.  
  46. for app in apps:
  47.     label = tk.Label(frame, text=app)
  48.     label.pack()
  49.  
  50. root.mainloop()
  51.  
  52. with open('save.txt', 'w') as f:
  53.     for app in apps:
  54.         f.write(app+',')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement