OpenFiles_1.py 1.1 KB

1234567891011121314151617181920212223242526272829303132
  1. def uploadTCLFile(self):
  2. files = filedialog.askopenfilenames(
  3. initialdir=os.getcwd(),
  4. title="Choose TCL files",
  5. filetypes=(("TCL Files", "*.tcl"),)
  6. )
  7. try:
  8. for tf in files:
  9. if tf == "":
  10. self.tclUploadVar.set("")
  11. return
  12. tf = open(tf) # or tf = open(tf, 'r')
  13. # copy file over to tcl locations
  14. shutil.copy(tf.name, os.getcwd() + os.path.join("\\lab_tcl"))
  15. tf.close()
  16. except:
  17. self.tclStatusLabel.configure(style="Red.TLabel")
  18. self.tclUploadVar.set("An Error Occurred")
  19. return
  20. if len(files) == 1:
  21. # Generate an animation for the result
  22. self.tclStatusLabel.configure(style="Green.TLabel")
  23. self.tclUploadVar.set("Copied " + files[0][files[0].rfind("/") + 1:len(files[0])])
  24. elif len(files) > 1:
  25. self.tclStatusLabel.configure(style="Green.TLabel")
  26. self.tclUploadVar.set("Copied " + str(len(files)) + " Files")
  27. elif len(files) == 0:
  28. self.tclStatusLabel.configure(style="TLabel")
  29. self.tclUploadVar.set("")