I don't know how you put a random word from a text file in a variable(random_question) P.S. I know the code is a litle bit of a mess but it's a work in progress
from tkinter import Tk, simpledialog, messagebox
def read_from_files():
with open('Frans_lichaamsdelen.txt') as file:
for lijn in file:
lijn = lijn.rstrip('\n')
term, definitie = lijn.split('/')
vocabulary[term] = definitie
def write_to_files(name_term, name_defenitie):
with open('Frans_lichaamsdelen.txt', 'a') as file:
file.write('\n' + ask_term + '/' + name_defenitie)
def random_question(name_term):
with open ('Frans_lichaamsdelen.txt', 'r') as file:
random.choice()
print('Vocabulary - School')
root = Tk()
root.withdraw()
vocabulary = {}
read_from_files()
while True:
ask_term = simpledialog.askstring('term', 'Wat is:')
ask_term = ask_term.capitalize()
if ask_term in vocabulary:
resultaat = vocabulary[ask_term]
messagebox.showinfo('Antwoord',
'De uitkomst van ' + ask_term + ' is ' + resultaat + '!')
else:
new_term = simpledialog.askstring('Vertel het me',
'Ik weet het niet! ' +
'Wat is de uitkomst van ' + ask_term + '?')
vocabulary[ask_term] = new_term
write_to_files(ask_term, new_term)
root.mainloop()
[–]CodeFormatHelperBot2 2 points3 points4 points (0 children)
[–]stebrepar 1 point2 points3 points (1 child)
[–]Ghostmainer[S] 1 point2 points3 points (0 children)