Guest User

Untitled

a guest
May 23rd, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.05 KB | None | 0 0
  1. file_in_use = 'farsi_words'
  2.  
  3. def defaultFile(filename):
  4. file_in_use = filename
  5. return file_in_use
  6.  
  7. bN = Button(f0, text = 'Nouns', command =lambda: defaultFile('farsi_words'))
  8. bN.pack(side='left')
  9. bN.bind("<Button-1>",
  10. bV = Button(f0, text = 'Verbs', command =lambda: defaultFile('farsi_verbs'))
  11. bV.pack(side='left')
  12. bA = Button(f0, text = 'Adjectives', command =lambda: defaultFile('farsi_adjectives'))
  13. bA.pack(side='left')
  14. bP = Button(f0, text = 'Prepositions', command =lambda: defaultFile('farsi_preps'))
  15. bP.pack(side='left')
  16.  
  17. def commit(file_in_use):
  18. word = e1.get()
  19. definition = e2.get()
  20. appendFile = open(file_in_use, 'a')#was this defined before def?
  21. appendFile.write('n' + word + ': ' + definition)
  22. appendFile.close()
  23. e1.delete(0, 'end')
  24. e2.delete(0, 'end')
  25.  
  26. def review(file_in_use):
  27. t1.delete('1.0', END)
  28. readFile = open(file_in_use, 'r')
  29. size = 0
  30. splitList = []
  31. for line in readFile:
  32. splitWord = line.split(':')
  33. splitWord = splitWord[0].strip('n ')
  34. splitList.append(splitWord)
  35. size += 1
  36.  
  37. n = random.randint(0, size - 1)
  38. t1.insert(INSERT, splitList[n] + 'n')
  39. readFile.close()
  40.  
  41. def answer(file_in_use):
  42. word = e3.get()
  43. def1 = t1.get('1.0','end-1c')
  44. def1 = def1.strip('n')
  45. readFile = open(file_in_use, 'r')
  46. for line in readFile:
  47. splitWord = line.split(': ')
  48. if def1 == splitWord[0].strip('n'):
  49. if word == splitWord[1].strip('n'):
  50. t1.insert(INSERT, 'Good job!')
  51. else:
  52. t1.insert(INSERT, 'Not quite! Good try =)')
  53. readFile.close()
  54.  
  55. def hint(file_in_use):
  56. def1 = t1.get('1.0','2.0')
  57. def1 = def1.strip('n')
  58. readFile = open(file_in_use, 'r')
  59.  
  60. for line in readFile:
  61. splitWord = line.split(': ')
  62. if def1 == splitWord[0].strip('n'):
  63. hint = splitWord[1]
  64.  
  65. hint1 = t1.get('2.0','end-1c')
  66. lenHint1 = len(hint1)
  67. if lenHint1 >= len(hint):
  68. pass
  69. else:
  70. t1.insert(INSERT, hint[lenHint1])
  71. print (hint1)
  72. readFile.close()
Add Comment
Please, Sign In to add comment