From d6173e8c2df72208f23801538c025fc56158674c Mon Sep 17 00:00:00 2001 From: Zeftax <46405012+Zeftax@users.noreply.github.com> Date: Wed, 28 Aug 2019 00:56:42 +0200 Subject: [PATCH] Add files via upload --- angtest.tst | 6 ++ programfiles/default.tst | 3 + programfiles/highScore.txt | 1 + vyzkousejme.py | 127 +++++++++++++++++++++++++++++++++++++ 4 files changed, 137 insertions(+) create mode 100644 angtest.tst create mode 100644 programfiles/default.tst create mode 100644 programfiles/highScore.txt create mode 100644 vyzkousejme.py diff --git a/angtest.tst b/angtest.tst new file mode 100644 index 0000000..e4a72b7 --- /dev/null +++ b/angtest.tst @@ -0,0 +1,6 @@ +CESTINA/ANGLICTINA +0 +apple/jablko +car,automobile/auto,automobil +chopper,helicopter/vrtulnik,helikoptera +pear/hruska \ No newline at end of file diff --git a/programfiles/default.tst b/programfiles/default.tst new file mode 100644 index 0000000..7858aea --- /dev/null +++ b/programfiles/default.tst @@ -0,0 +1,3 @@ +EXAMPLE TEST SUBJECT 1/EXAMPLE TEST SUBJECT 2 +0 +question will appear here/question will appear here \ No newline at end of file diff --git a/programfiles/highScore.txt b/programfiles/highScore.txt new file mode 100644 index 0000000..c227083 --- /dev/null +++ b/programfiles/highScore.txt @@ -0,0 +1 @@ +0 \ No newline at end of file diff --git a/vyzkousejme.py b/vyzkousejme.py new file mode 100644 index 0000000..0fc2b0f --- /dev/null +++ b/vyzkousejme.py @@ -0,0 +1,127 @@ +from tkinter import * +from tkinter import filedialog +from tkinter import messagebox +import time +import random + + +def newQuestion(): + global questionPlace + questionPlace = random.randint(0, len(test[2])-1) + newQuestion = test[2][questionPlace][0] + question.set(newQuestion) + + +def on_closing(): + if messagebox.askokcancel("Quit", "Do you want to quit?"): + root.destroy() + + +def submitAnswer(): + global score + if answerEntry.get().lower() in test[3] [questionPlace]: + score += 1 + currentScore.set('Score: %s' % (score)) + else: + score = 0 + currentScore.set('Score: %s' % (score)) + if score > int(test[4]): + test[4] = score + highScore.set('High score: %s' % (test[4])) + answerEntry.delete(0, 'end') + newQuestion() + + +def formatTest(filepath): + global score + with open(filepath) as file: + file = file.readlines() + + nazev1 = file[0].split('/')[0] + nazev2 = file[0].split('/')[1] + + sloupec1 = [] + sloupec2 = [] + + highScore = file[1].strip('/n') + score = 0 + + for line in file[2:]: + currentline = line.strip('\n') + currentline = currentline.split('/') + sloupec1.append(currentline[0].split(',')) + sloupec2.append(currentline[1].split(',')) + + return nazev1, nazev2, sloupec1, sloupec2, highScore + + +def getExtension(filename): # returns the last four characters in a filename as a string + return filename[-4:None] + + +def openTest(): + global test + gotfile = False + filepath = None + while not gotfile: + filepath = filedialog.askopenfilename(title='Select test file') + if getExtension(filepath) == '.tst': + gotfile = True + else: + messagebox.showinfo("CHYBA: nerozeznany soubor", "Omlovame se ale soubory tupu '%s' nepodporujeme, podporujeme pouze soubory typu '.tst'" % (getExtension(filepath))) + test = list(formatTest(filepath)) + newQuestion() + + +def makeMenu(root): + menu = Menu(root) + root.config(menu=menu) + + menu.add_command(label='Open', command=openTest) + menu.add_command(label='Switch sides', command=None) + + return menu + + +def makeRoot(): + root = Tk() + root.geometry('500x400') + root.title('Vyzkousej me') + root.configure(bg="gray") + return root + + +root = makeRoot() +menu = makeMenu(root) +test = list(formatTest('programfiles/default.tst')) +questionPlace = 0 +score = 0 + +currentScore = StringVar() +highScore = StringVar() +question = StringVar() +timeMultiplier = StringVar() + +currentScoreLabel = Label(root, textvariable=currentScore, bg='gray') +highScoreLabel = Label(root, textvariable=highScore, bg='gray') +questionLabel = Label(root, textvariable=question) +answerEntry = Entry(root) +answerButton = Button(root, text='submit', command=submitAnswer) +timeMultiplierLabel = Label(root, textvariable=timeMultiplier, bg='gray') + +currentScoreLabel.grid(row=0, column=0, columnspan=2, sticky=W) +highScoreLabel.grid(row=0, column=2, columnspan=2, sticky=E) +questionLabel.grid(row=1, column=1, sticky=W) +answerEntry.grid(row=1, column=2, sticky=E) +answerButton.grid(row=1, column=3, sticky=W) +timeMultiplierLabel.grid(row=2, column=0, columnspan=4) + + +currentScore.set('Score: %s' %(score)) +highScore.set('High score: %s' %(test[4])) +question.set('question will appear here') +timeMultiplier.set('Time multiplier is: 0') + +root.protocol("WM_DELETE_WINDOW", on_closing) + +root.mainloop()