OpenFiles_6.py 522 B

1234567891011121314151617
  1. def openStudentListFile(self):
  2. tf = filedialog.askopenfilename(
  3. initialdir=os.getcwd() + os.path.join("\\studentlists"),
  4. title="Choose Student List file",
  5. filetypes=(("Text Files", "*.txt"),)
  6. )
  7. if tf == "":
  8. self.studentListVar.set("")
  9. self.chooseStudentsLabel['text'] = ""
  10. return
  11. tf = open(tf) # or tf = open(tf, 'r')
  12. self.studentListVar.set(tf.name)
  13. self.chooseStudentsLabel['text'] = tf.name[tf.name.rfind("/") + 1:len(tf.name)]
  14. tf.close()