def dAllVoice(workdoc): j = 1 source = "" shc = 0 ttsc = 0 t0 = time.time() with open(workdoc,'r', encoding = 'utf-8') as f: lines = f.read().split("\n") f.close() for i in lines: if j ==0: i = i.split(",") fdir ="{}\\{}\\{}\\{}".format(consts.cwd(),consts.fname(),i[11],i[12]) file = "{}\\{}\\{}\\{}\\{}.mp3".format(consts.cwd(),consts.fname(),i[11],i[12],i[0].replace("?", "qChar")) file = file.replace(" .mp3", ".mp3") file = file.replace("..mp3", ".mp3") file = file.replace("/", "slashChar") file = file.lower() if not os.path.isdir(fdir): os.makedirs(fdir) if not os.path.isfile(file): try: with open(file, 'wb') as f: f.write(getVoice(i[0].replace('commaChar',",").replace("qChar","?").replace("slashChar","/").lower())) source = "shtooka" shc = shc + 1 except Exception as e: tts = gTTS(text=i[0].replace('commaChar',",").replace("qChar","?").replace("slashChar","/").lower(), lang=i[14]) tts.save("{}".format(file)) source = "tts" ttsc = ttsc + 1 progress = int(i[10])/len(lines) progress = math.floor(progress*100) os.system('cls') print('\r[{}] {}% {}/{} {} {} tts:{} shtooka:{} time:{}'.format('#'*math.floor(progress/10) + ' '*(10-math.floor(progress/10)), progress, i[10], len(lines), file, source, ttsc, shc, math.floor(time.time() - t0)), end = "\r", flush = True) else: j = 0 #if __name__ == "__main__": # getVoice('пока', 'ru')
def play(i, a = False): file = "{}\\{}\\{}\\{}\\{}.mp3".format(consts.cwd(),consts.fname(),i[11],i[12],(i[0] if not a else i[1]).replace("?", "qChar")) file = file.replace(" .mp3", ".mp3") file = file.replace("..mp3", ".mp3") file = file.replace('.mp3.mp3', '.mp3') file = file.replace("/", "slashChar") file = file.lower() pygame.mixer.music.load(file) pygame.mixer.music.set_volume(volume) pygame.mixer.music.play() while pygame.mixer.music.get_busy(): pass
def __init__(self, master, *args, **kwargs): tk.Entry.__init__(self, master, *args, **kwargs) self.bind('<Key>', self.check) self.bind('<Shift-Key-Multi_key>', lambda e: self.check(e, True)) self.bind('<Shift-Key>', lambda e: self.check(e, True)) self.bind('<Control-Key-question>', self.CKey) self.bind('<Control-Key-Multi_key>', self.CKey) confile = consts.cwd() + '\layoutMaps.ini' config = configparser.ConfigParser() config.read(confile, encoding='utf-8') self.keys = {} for k in config: keyset = {} for i in config[k]: if ', ' in i: j = i.split(', ') keyset[int(j[0]), int(j[1])] = config[k][i] else: keyset[int(i)] = config[k][i] self.keys[k] = keyset self.last = None
def preload(i, r = False): if i[14] == 'none':return if r: if 'img-' in i[1]: ifdir ="{}\\{}\\{}\\{}\\{}\\".format(consts.cwd(),consts.fname(),i[11],i[12],consts.images()) ifile = "{}\\{}\\{}\\{}\\{}\\{}".format(consts.cwd(),consts.fname(),i[11],i[12],consts.images(),i[1].split('/')[len(i[1].split('/')) - 1]) if not os.path.isdir(ifdir): os.makedirs(ifdir) if not os.path.isfile(ifile): with open(ifile, 'wb') as f: shutil.copyfileobj(getFile(img = i[1].split('img-')[1]), f) return elif 'audio-' in i[1]: ifdir ="{}\\{}\\{}\\{}\\".format(consts.cwd(),consts.fname(),i[11],i[12]) ifile = "{}\\{}\\{}\\{}\\{}".format(consts.cwd(),consts.fname(),i[11],i[12],'audio-' + i[1].split('/')[len(i[1].split('/')) - 1]) if not os.path.isdir(ifdir): os.makedirs(ifdir) if not os.path.isfile(ifile): with open(ifile, 'wb') as f: f.write(getFile(audio = i[1].split('audio-')[1])) return elif not r: if 'audio-' in i[1]: return fdir ="{}\\{}\\{}\\{}".format(consts.cwd(),consts.fname(),i[11],i[12]) file = "{}\\{}\\{}\\{}\\{}.mp3".format(consts.cwd(),consts.fname(),i[11],i[12],i[0].replace("?", "qChar")) file = file.replace(" .mp3", ".mp3") file = file.replace("..mp3", ".mp3") file = file.replace("/", "slashChar") file = file.lower() if not os.path.isdir(fdir): os.makedirs(fdir) if not os.path.isfile(file): try: with open(file, 'wb') as f: f.write(getFile(word = i[0], lang = i[14])) except: tts = gTTS(text=i[0].replace("commaChar", ","), lang=i[14]) tts.save("{}".format(file))
def historyFiles(self): self.init_vals() for i in self.controller.dandl: self.controller.update() self.hfiles.append('{}\\{}\\{}{}'.format(consts.cwd(), consts.fname(), i, consts.hwdoc())) for j in self.hfiles: self.controller.update() try: deckName = j.split("\\")[6] self.hfilesread[deckName] = [] for line in mycsv.read(j).split("\n"): self.controller.update() if not line == '': self.hfilesread[deckName].append(line.split(',')) except: pass for k in self.hfilesread: self.controller.update() for n, i in enumerate(self.hfilesread[k]): self.controller.update() self.allHis.append(i) # l = [] p = [] seconds = 0 for i in self.allHis: self.controller.update() if i[16] == mycsv.curdate and i[15] == "review": l.append(i) seconds += float(i[18]) if i[16] == mycsv.curdate and i[15] == "learn": p.append(i) self.donetoday = len(l) self.learnedtoday = len(p) self.minutesLearn, self.secondsLearn = divmod(seconds, 60) self.hoursLearn, self.minutesLearn = divmod(self.minutesLearn, 60) j = self.convertStrTimeAddDays(mycsv.curdate) l = self.convertStrTimeAddDays(mycsv.curdate) for i in self.controller.total: self.controller.update() k = self.convertStrTimeAddDays(i.split(",")[8]) if k[1] > j[1]: j = k if k[1] < l[1]: l = k self.latestdate = j self.earliestdate = l self.startdate = self.earliestdate while not self.startdate[1] == self.latestdate[1]: self.controller.update() self.startdate = self.convertStrTimeAddDays(self.startdate[0], days=1) if not self.startdate[0] in self.days: self.days[self.startdate[0]] = [] for i in self.controller.total: if i.split(",")[8] == self.startdate[0] and i.split( ',')[3] == 'yes': self.days[self.startdate[0]].append(i)
def makeBackup(): dal = srs.findDecksAndLevels() for folder, subfolders, files in os.walk("{}\{}".format( consts.cwd(), consts.fname())): subs = subfolders for i in subs: if i in dal: for folder, subfolders, files in os.walk("{}\{}\{}".format( consts.cwd(), consts.fname(), i)): nsubs = subfolders for j in nsubs: if j in dal[i]: for folder, subfolders, files in os.walk( "{}\{}\{}\{}".format( consts.cwd(), consts.fname(), i, j)): for f in files: nnsubs = [x[0].lower() for x in dal[i][j]] f = f.replace(".mp3", "").replace( "qchar", "?").replace("slashchar", "/") if f in nnsubs: pass else: if os.path.isfile("{}\{}.mp3".format( folder, f)): if not 'audio-' in "{}\{}.mp3".format( folder, f): os.remove("{}\{}.mp3".format( folder, f)) else: try: if not 'audio-' in "{}\{}".format( folder, f.replace( "?", "qchar") + '.mp3'): os.remove("{}\{}".format( folder, f.replace( "?", "qchar") + '.mp3')) except: pass else: for folder, subfolders, files in os.walk( "{}\{}\{}\{}".format( consts.cwd(), consts.fname(), i, j), topdown=False): for file in files: os.remove("{}\{}".format(folder, file)) os.rmdir(folder) else: for folder, subfolders, files in os.walk("{}\{}\{}".format( consts.cwd(), consts.fname(), i), topdown=False): for file in files: os.remove("{}\{}".format(folder, file)) os.rmdir(folder) d = str(datetime.datetime.now()).split(" ")[0] if not os.path.isdir(consts.backups() + d): os.makedirs(consts.backups() + d) for folder, subfolders, files in os.walk(consts.backups() + d): if len(files) == 0: p = consts.backups() + d + '\\session1.zip' else: p = consts.backups() + d + '\\session{}.zip'.format(len(files) + 1) mzip = zipfile.ZipFile(p, 'w') for folder, subfolders, files in os.walk(consts.cwd()): for file in files: if file.endswith('.csv'): mzip.write(os.path.join(folder, file), os.path.relpath(os.path.join(folder, file), consts.cwd()), compress_type=zipfile.ZIP_DEFLATED) mzip.close() for folder, subfolders, files in os.walk(consts.backups() + d): f = (consts.backups() + d + "\\" + files[len(files) - 2]) fc = Crc32Hasher(f) pc = Crc32Hasher(p) if fc == pc and not f == p: os.remove(p) for folder, subfolders, files in os.walk(consts.backups()): for i in subfolders: j = i.replace("-", "/").split("/") k = "{}/{}/{}".format(j[2], j[1], j[0]) if (convertStrTimeAddDays(mycsv.curdate)[1] - convertStrTimeAddDays(k)[1]).days > 5: for folder, subfolders, files in os.walk(consts.backups() + i): for file in files: os.remove(consts.backups() + i + "\\" + file) os.rmdir(consts.backups() + i)
def checkChanges(self): if self.monthEntry.get() == str(consts.month()) and self.newPerLessonEntry.get() == str(consts.newPerLesson()) and self.reviewPerlessonEntry.get() == str(consts.reviewPerLesson()) and self.workdocEntry['text'] == consts.workdoc() and self.cwdEntry['text'] == consts.cwd(): self.saveButton['state'] = tk.DISABLED else: self.saveButton['state'] = tk.ACTIVE
def f(self): mdir = filedialog.askdirectory(initialdir = self.cwdEntry['text']).replace("/","\\"); self.cwdEntry['text'] = mdir if mdir else consts.cwd(); self.checkChanges() self.cwdBrowser = tk.Button(self, text = "Change directory", command = lambda: f(self))
def createWidgets(self): # [GENERAL] # cwd = C:\Users\Jc\Desktop\srs rus # month = 30 # workdoc = C:\Users\Jc\Desktop\srs rus\sentences.csv # hwdoc = \history.csv # fname = data # backups = C:\Users\Jc\Desktop\srs rus\backups\ # newperlesson = 5 # reviewperlesson = 25 self.cwdLabel = tk.Label(self, text = "Current working directory:") self.cwdLabel.grid(row = 0, column = 0) self.cwdEntry = tk.Label(self, text = consts.cwd()) self.cwdEntry.grid(row = 0, column = 1) def f(self): mdir = filedialog.askdirectory(initialdir = self.cwdEntry['text']).replace("/","\\"); self.cwdEntry['text'] = mdir if mdir else consts.cwd(); self.checkChanges() self.cwdBrowser = tk.Button(self, text = "Change directory", command = lambda: f(self)) self.cwdBrowser.grid(row = 0, column=2) self.workdocLabel = tk.Label(self, text = "Current workdoc:") self.workdocLabel.grid(row = 1, column = 0) self.workdocEntry = tk.Label(self, text = consts.workdoc()) self.workdocEntry.grid(row = 1, column = 1) def k(self): mdir = filedialog.askopenfilename(initialfile = self.workdocEntry['text'], filetypes = (('csv files','*.csv'),)).replace("/","\\"); self.workdocEntry['text'] = mdir if mdir else consts.workdoc(); self.checkChanges() self.workdocBrowser = tk.Button(self, text = "Change file", command = lambda: k(self)) self.workdocBrowser.grid(row = 1, column=2) self.monthLabel = tk.Label(self, text = "Month:") self.monthLabel.grid(row = 2, column = 0) self.monthEntry = tk.Entry(self, validate = 'key', validatecommand = (self.register(lambda x: x.isdigit()), '%S')) self.monthEntry.insert(tk.END, consts.month()) self.monthEntry.grid(row = 2, column = 1) # self.hwdocLabel = tk.Label(self, text = "Current hwdoc:") # self.hwdocLabel.grid(row = 3, column = 0) # self.hwdocEntry = tk.Label(self, text = consts.hwdoc()) # self.hwdocEntry.grid(row = 3, column = 1) # self.fnameLabel = tk.Label(self, text = "Current fname:") # self.fnameLabel.grid(row = 4, column = 0) # self.fnameEntry = tk.Label(self, text = consts.fname()) # self.fnameEntry.grid(row = 4, column = 1) # self.backupsLabel = tk.Label(self, text = "Current backups directory:") # self.backupsLabel.grid(row = 5, column = 0) # self.backupsEntry = tk.Label(self, text = consts.backups()) # self.backupsEntry.grid(row = 5, column = 1) self.newPerLessonLabel = tk.Label(self, text = "Current newPerLesson:") self.newPerLessonLabel.grid(row = 6, column = 0) self.newPerLessonEntry = tk.Entry(self, validate = 'key', validatecommand = (self.register(lambda x: x.isdigit()), '%S')) self.newPerLessonEntry.insert(tk.END, consts.newPerLesson()) self.newPerLessonEntry.grid(row = 6, column = 1) self.reviewPerlessonLabel = tk.Label(self, text = "Current reviewPerLesson:") self.reviewPerlessonLabel.grid(row = 7, column = 0) self.reviewPerlessonEntry = tk.Entry(self, validate = 'key', validatecommand = (self.register(lambda x: x.isdigit()), '%S')) self.reviewPerlessonEntry.insert(tk.END, consts.reviewPerLesson()) self.reviewPerlessonEntry.grid(row = 7, column = 1) self.buttonGoBack = tk.Button(self, text = "Go Back", command = self.goMainMenu) self.buttonGoBack.grid(row = 0, column=3) self.saveButton = tk.Button(self, text = "Save changes", command = self.saveChanges, state = tk.DISABLED) self.saveButton.grid(row = 8, columnspan = 2) for w in self.winfo_children(): if isinstance(w, tk.Entry): w.bind('<Key>', lambda x: self.after(0, self.checkChanges))
def doLearnLesson(sentences, root, tWidget, eWidget, tagsWidget, cWidget): curdate = "{}/{}/{}".format(datetime.now().day, datetime.now().month, datetime.now().year) gotAnswer = False completed = [] while len(sentences) > 0: random.shuffle(sentences) for n, i in enumerate(sentences): root.line = i.split(",") eWidget.delete(0, len(eWidget.get())) if not 'img-' in root.line[1].replace( 'commaChar', ',') and not 'audio-' in root.line[1].replace( 'commaChar', ','): tWidget.configure(text=root.line[1].replace("commaChar", ","), image=None) tWidget.unbind('<Button-1>') elif 'img-' in root.line[1].replace('commaChar', ','): imgFile = "{}\\{}\\{}\\{}\\{}\\{}".format( consts.cwd(), consts.fname(), root.line[11], root.line[12], consts.images(), root.line[1].replace('img-', '')) im = Image.open(imgFile) #im = im.resize(size=(50,50)) img = ImageTk.PhotoImage(im) tWidget.img = img tWidget.configure(image=img, text='') tWidget.unbind('<Button-1>') elif 'audio-' in root.line[1].replace('commaChar', ','): img = ImageTk.PhotoImage(audLight) tWidget.img = img tWidget.configure(image=img, text='') def audPlay(): img = ImageTk.PhotoImage(audDark) tWidget.img = img tWidget.configure(image=img, text='') audio.play(root.line, a=True) img = ImageTk.PhotoImage(audLight) tWidget.img = img tWidget.configure(image=img, text='') tWidget.bind( '<Button-1>', lambda x: threading.Thread( target=audPlay, daemon=True).start()) tagsWidget.configure( text=root.line[2].replace("commaChar", ",") ) if not root.line[2] == "none" else tagsWidget.configure(text="") if root.line[3] == 'no': cAnswerEntry = tk.Label( root, text=root.line[0].replace("commaChar", ",").replace(".", ""), font=(lambda x: cAnswerEntry.cget('font'), 32), width=50, wraplength=1255) cAnswerEntry.grid(row=4, column=0, columnspan=2, rowspan=1) cWidget.set(0) root.update() if not 'audio-' in root.line[1].replace('commaChar', ','): audio.preload(root.line) audio.play(root.line) else: img = ImageTk.PhotoImage(audDark) tWidget.img = img tWidget.configure(image=img, text='') root.update() audio.play(root.line, a=True) img = ImageTk.PhotoImage(audLight) tWidget.img = img tWidget.configure(image=img, text='') root.line[3] = 'step0' else: cWidget.set(int(root.line[3].split("step")[1])) eWidget.focus() gotAnswer = False root.lineEdited = False userinput, time = waitForAnswer(gotAnswer, root, eWidget, root.line) try: root.editEntrytl.destroy() except: pass if userinput == root.line[0].lower().replace(".", ""): eWidget["bg"] = "lime green" eWidget["fg"] = "white" root.line[3] = "step{}".format( int(root.line[3].split("step")[1]) + 1) cWidget.set(int(root.line[3].split("step")[1])) root.update() root.line = ','.join(root.line) sentences[n] = root.line else: eWidget["bg"] = "red" eWidget["fg"] = "white" root.line[3] = "no-step{}".format( int(root.line[3].split("step")[1])) root.update() root.line = ','.join(root.line) sentences[n] = root.line cAnswerEntry.destroy() afterAnswer(eWidget, root.line.split(","), root) if not 'no' in root.line.split(",")[3]: if int(root.line.split(",")[3].split('step')[1]) == 6: root.line = root.line.split(",") root.line[3] = 'yes' root.line[6] = curdate root.line[8] = addDays(root.line) root.line = ','.join(root.line) completed.append(root.line) del sentences[n] else: root.line = root.line.split(",") root.line[3] = root.line[3].split("no-")[1] root.line = ','.join(root.line) sentences[n] = root.line root.update() for widget in root.winfo_children(): widget.destroy() root.update() text = tk.Label(root, font=(lambda x: Label.cget('font'), 32), text="lesson Done!") text.grid() root.update() mycsv.write(consts.workdoc(), mstr=completed, lesson=True, review=False, learn=True)
def doReviewLesson(sentences, root, tWidget, eWidget, tagsWidget, cWidget): curdate = "{}/{}/{}".format(datetime.now().day, datetime.now().month, datetime.now().year) completed = [] uncompleted = [] redo = [] hissentences = [] gotAnswer = False while len(sentences) > 0: for n, i in enumerate(sentences): cWidget.configure(text="{}/{}".format( len(completed) + 1, len(sentences) + len(completed) + len(uncompleted) + len(redo))) # if len(uncompleted) > 0: # if random.randint(0,4) == 1: # i = uncompleted[len(uncompleted) - 1] # n = len(uncompleted) - 1 # fromUncomplete = True root.line = i.split(",") eWidget.delete(0, len(eWidget.get())) if not 'img-' in root.line[1].replace( 'commaChar', ',') and not 'audio-' in root.line[1].replace( 'commaChar', ','): tWidget.configure(text=root.line[1].replace("commaChar", ","), image=None) tWidget.unbind('<Button-1>') elif 'img-' in root.line[1].replace('commaChar', ','): imgFile = "{}\\{}\\{}\\{}\\{}\\{}".format( consts.cwd(), consts.fname(), root.line[11], root.line[12], consts.images(), root.line[1].replace('img-', '')) im = Image.open(imgFile) img = ImageTk.PhotoImage(im) tWidget.img = img tWidget.configure(image=img, text='') tWidget.unbind('<Button-1>') elif 'audio-' in root.line[1].replace('commaChar', ','): img = ImageTk.PhotoImage(audLight) tWidget.img = img tWidget.configure(image=img, text='') def audPlay(): img = ImageTk.PhotoImage(audDark) tWidget.img = img tWidget.configure(image=img, text='') audio.play(root.line, a=True) img = ImageTk.PhotoImage(audLight) tWidget.img = img tWidget.configure(image=img, text='') tWidget.bind( '<Button-1>', lambda x: threading.Thread( target=audPlay, daemon=True).start()) tagsWidget.configure( text=root.line[2].replace("commaChar", ",") ) if not root.line[2] == "none" else tagsWidget.configure(text="") eWidget.focus() gotAnswer = False root.lineEdited = False res = waitForAnswer(gotAnswer, root, eWidget, root.line) userinput = res[0] wait = res[1] try: root.editEntrytl.destroy() except: pass if root.lineEdited == False: if userinput == root.line[0].lower().replace(".", ""): eWidget["bg"] = "lime green" eWidget["fg"] = "white" root.update() root.line[4] = str(int(root.line[4]) + 1) root.line[5] = str(int(root.line[5]) + 1) root.line[6] = curdate root.line[7] = 'success' root.line[9] = str(int(root.line[9]) + 1) root.line[8] = addDays(root.line) nhisline = root.line[:] nhisline.append('none') nhisline.append("-1") nhisline.append(str(datetime.now().strftime('%H:%M:%S'))) nhisline.append(str(wait)) hissentences.append(nhisline) root.line = ','.join(root.line) completed.append(root.line) del sentences[n] else: eWidget["bg"] = "red" eWidget["fg"] = "white" root.update() root.line[4] = str(int(root.line[4]) + 1) root.line[6] = curdate root.line[7] = 'fail' root.line[8] = addDays(root.line) root.line = ','.join(root.line) redo.append(root.line) del sentences[n] else: if root.line[13] == "no": del sentences[n] root.line = ','.join(root.line) sentences.append(root.line) elif root.line[13] == "yes": del sentences[n] nhisline = root.line[:] nhisline.append('none') nhisline.append("-1") nhisline.append(str(datetime.now().strftime('%H:%M:%S'))) nhisline.append('-1') hissentences.append(nhisline) root.line = ','.join(root.line) completed.append(root.line) afterAnswer(eWidget, root.line.split(","), root) root.lineEdited = False while len(redo) > 0: for n, i in enumerate(redo): cWidget.configure(text="{}/{}".format( len(completed) + 1, len(sentences) + len(completed) + len(uncompleted) + len(redo))) root.line = i.split(",") if not 'img-' in root.line[1].replace( 'commaChar', ',') and not 'audio-' in root.line[1].replace( 'commaChar', ','): tWidget.configure(text=root.line[1].replace( "commaChar", ","), image=None) tWidget.unbind('<Button-1>') elif 'img-' in root.line[1].replace('commaChar', ','): imgFile = "{}\\{}\\{}\\{}\\{}\\{}".format( consts.cwd(), consts.fname(), root.line[11], root.line[12], consts.images(), root.line[1].replace('img-', '')) im = Image.open(imgFile) #im = im.resize(size=(50,50)) img = ImageTk.PhotoImage(im) tWidget.img = img tWidget.configure(image=img, text='') tWidget.unbind('<Button-1>') elif 'audio-' in root.line[1].replace('commaChar', ','): img = ImageTk.PhotoImage(audLight) tWidget.img = img tWidget.configure(image=img, text='') def audPlay(): img = ImageTk.PhotoImage(audDark) tWidget.img = img tWidget.configure(image=img, text='') audio.play(root.line, a=True) img = ImageTk.PhotoImage(audLight) tWidget.img = img tWidget.configure(image=img, text='') tWidget.bind( '<Button-1>', lambda x: threading.Thread(target=audPlay, daemon=True).start()) gotAnswer = False root.lineEdited = False cAnswerEntry = tk.Label( root, text=root.line[0].lower().replace(".", ""), font=(lambda x: cAnswerEntry.cget('font'), 32), width=50, wraplength=1255) cAnswerEntry.grid(row=4, column=0, columnspan=2, rowspan=1) res = waitForAnswer(gotAnswer, root, eWidget, root.line) userinput = res[0] wait = res[1] + wait try: root.editEntrytl.destroy() except: pass if root.lineEdited == False: if userinput == root.line[0].lower().replace(".", ""): eWidget["bg"] = "lime green" eWidget["fg"] = "white" root.update() root.line[9] = str(1) root.line[8] = addDays(root.line) root.line.append(str(wait)) root.line = ','.join(root.line) uncompleted.append(root.line) del redo[n] else: eWidget["bg"] = "red" eWidget["fg"] = "white" root.line = ','.join(root.line) redo.append(root.line) del redo[n] root.update() else: if root.line[13] == "no": del redo[n] root.line = ','.join(root.line) redo.append(root.line) elif root.line[13] == "yes": del redo[n] nhisline = root.line[:] nhisline.append('none') nhisline.append("-1") nhisline.append( str(datetime.now().strftime('%H:%M:%S'))) nhisline.append('-1') hissentences.append(nhisline) root.line = ','.join(root.line) completed.append(root.line) afterAnswer(eWidget, root.line.split(","), root) root.lineEdited = False cAnswerEntry.destroy() while len(uncompleted) > 0: for n, i in enumerate(uncompleted): cWidget.configure(text="{}/{}".format( len(completed) + 1, len(sentences) + len(completed) + len(uncompleted))) root.line = i.split(",") if not 'img-' in root.line[1].replace( 'commaChar', ',') and not 'audio-' in root.line[1].replace( 'commaChar', ','): tWidget.configure(text=root.line[1].replace("commaChar", ","), image=None) tWidget.unbind('<Button-1>') elif 'img-' in root.line[1].replace('commaChar', ','): imgFile = "{}\\{}\\{}\\{}\\{}\\{}".format( consts.cwd(), consts.fname(), root.line[11], root.line[12], consts.images(), root.line[1].replace('img-', '')) im = Image.open(imgFile) #im = im.resize(size=(50,50)) img = ImageTk.PhotoImage(im) tWidget.img = img tWidget.configure(image=img, text='') tWidget.unbind('<Button-1>') elif 'audio-' in root.line[1].replace('commaChar', ','): img = ImageTk.PhotoImage(audLight) tWidget.img = img tWidget.configure(image=img, text='') def audPlay(): img = ImageTk.PhotoImage(audDark) tWidget.img = img tWidget.configure(image=img, text='') audio.play(root.line, a=True) img = ImageTk.PhotoImage(audLight) tWidget.img = img tWidget.configure(image=img, text='') tWidget.bind( '<Button-1>', lambda x: threading.Thread( target=audPlay, daemon=True).start()) gotAnswer = False root.lineEdited = False cAnswerEntry = tk.Label(root, text=root.line[0].lower().replace(".", ""), font=(lambda x: cAnswerEntry.cget('font'), 32), width=50, wraplength=1255) cAnswerEntry.grid(row=4, column=0, columnspan=2, rowspan=1) res = waitForAnswer(gotAnswer, root, eWidget, root.line) userinput = res[0] wait = res[1] try: root.editEntrytl.destroy() except: pass if root.lineEdited == False: if userinput == root.line[0].lower().replace(".", ""): eWidget["bg"] = "lime green" eWidget["fg"] = "white" root.update() root.line[9] = str(1) root.line[8] = addDays(root.line) nhisline = root.line[:-1] nhisline.append('none') nhisline.append("-1") nhisline.append(str(datetime.now().strftime('%H:%M:%S'))) nhisline.append(str(float(root.line[15]) + wait)) del root.line[15] hissentences.append(nhisline) root.line = ','.join(root.line) completed.append(root.line) del uncompleted[n] else: eWidget["bg"] = "red" eWidget["fg"] = "white" root.update() root.line = ','.join(root.line) uncompleted.append(root.line) del uncompleted[n] else: if root.line[13] == "no": del uncompleted[n] root.line = ','.join(root.line[:-1]) uncompleted.append(root.line) elif root.line[13] == "yes": del uncompleted[n] nhisline = root.line[:-1] nhisline.append('none') nhisline.append("-1") nhisline.append(str(datetime.now().strftime('%H:%M:%S'))) nhisline.append('-1') hissentences.append(nhisline) root.line = ','.join(root.line[:-1]) completed.append(root.line) afterAnswer(eWidget, root.line.split(","), root) root.lineEdited = False root.update() for widget in root.winfo_children(): widget.destroy() root.update() text = tk.Label(root, font=(lambda x: Label.cget('font'), 32), text="Review Done!") text.grid() root.update() mycsv.write(consts.workdoc(), mstr=completed, lesson=True, review=True) mycsv.writeHistory(hissentences, tag='review')