added "swap sides"
This commit is contained in:
parent
d6173e8c2d
commit
9d8fb91f86
3 changed files with 61 additions and 23 deletions
|
@ -1,5 +1,5 @@
|
||||||
CESTINA/ANGLICTINA
|
CESTINA/ANGLICTINA
|
||||||
0
|
13
|
||||||
apple/jablko
|
apple/jablko
|
||||||
car,automobile/auto,automobil
|
car,automobile/auto,automobil
|
||||||
chopper,helicopter/vrtulnik,helikoptera
|
chopper,helicopter/vrtulnik,helikoptera
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
EXAMPLE TEST SUBJECT 1/EXAMPLE TEST SUBJECT 2
|
EXAMPLE TEST SUBJECT 1/EXAMPLE TEST SUBJECT 2
|
||||||
0
|
1
|
||||||
question will appear here/question will appear here
|
question will appear here/question will appear here
|
|
@ -1,10 +1,37 @@
|
||||||
from tkinter import *
|
from tkinter import *
|
||||||
from tkinter import filedialog
|
from tkinter import filedialog
|
||||||
from tkinter import messagebox
|
from tkinter import messagebox
|
||||||
import time
|
|
||||||
import random
|
import random
|
||||||
|
|
||||||
|
|
||||||
|
def swapSides():
|
||||||
|
global test
|
||||||
|
|
||||||
|
temp = test[2]
|
||||||
|
test[2] = test[3]
|
||||||
|
test[3] = temp
|
||||||
|
|
||||||
|
newQuestion()
|
||||||
|
|
||||||
|
|
||||||
|
def saveTest():
|
||||||
|
print(test)
|
||||||
|
with open(filepath, mode='w') as file:
|
||||||
|
file.write(test[0]+'/'+test[1])
|
||||||
|
file.write(str(test[4])+'\n')
|
||||||
|
for i in range(len(test[2])):
|
||||||
|
for j in range(len(test[2][i])):
|
||||||
|
file.write(test[2][i][j])
|
||||||
|
if j < len(test[2][i])-1:
|
||||||
|
file.write(',')
|
||||||
|
file.write('/')
|
||||||
|
for j in range(len(test[3][i])):
|
||||||
|
file.write(test[3][i][j])
|
||||||
|
if j < len(test[3][i])-1:
|
||||||
|
file.write(',')
|
||||||
|
file.write('\n')
|
||||||
|
|
||||||
|
|
||||||
def newQuestion():
|
def newQuestion():
|
||||||
global questionPlace
|
global questionPlace
|
||||||
questionPlace = random.randint(0, len(test[2])-1)
|
questionPlace = random.randint(0, len(test[2])-1)
|
||||||
|
@ -14,10 +41,11 @@ def newQuestion():
|
||||||
|
|
||||||
def on_closing():
|
def on_closing():
|
||||||
if messagebox.askokcancel("Quit", "Do you want to quit?"):
|
if messagebox.askokcancel("Quit", "Do you want to quit?"):
|
||||||
|
saveTest()
|
||||||
root.destroy()
|
root.destroy()
|
||||||
|
|
||||||
|
|
||||||
def submitAnswer():
|
def submitAnswer(uselessArgument):
|
||||||
global score
|
global score
|
||||||
if answerEntry.get().lower() in test[3] [questionPlace]:
|
if answerEntry.get().lower() in test[3] [questionPlace]:
|
||||||
score += 1
|
score += 1
|
||||||
|
@ -25,9 +53,9 @@ def submitAnswer():
|
||||||
else:
|
else:
|
||||||
score = 0
|
score = 0
|
||||||
currentScore.set('Score: %s' % (score))
|
currentScore.set('Score: %s' % (score))
|
||||||
if score > int(test[4]):
|
if score > test[4]:
|
||||||
test[4] = score
|
test[4] = score
|
||||||
highScore.set('High score: %s' % (test[4]))
|
highScore.set('High score: %d' % (test[4]))
|
||||||
answerEntry.delete(0, 'end')
|
answerEntry.delete(0, 'end')
|
||||||
newQuestion()
|
newQuestion()
|
||||||
|
|
||||||
|
@ -43,7 +71,7 @@ def formatTest(filepath):
|
||||||
sloupec1 = []
|
sloupec1 = []
|
||||||
sloupec2 = []
|
sloupec2 = []
|
||||||
|
|
||||||
highScore = file[1].strip('/n')
|
highScore = int(file[1].strip('\n'))
|
||||||
score = 0
|
score = 0
|
||||||
|
|
||||||
for line in file[2:]:
|
for line in file[2:]:
|
||||||
|
@ -61,6 +89,8 @@ def getExtension(filename): # returns the last four characters in a filename as
|
||||||
|
|
||||||
def openTest():
|
def openTest():
|
||||||
global test
|
global test
|
||||||
|
global filepath
|
||||||
|
saveTest()
|
||||||
gotfile = False
|
gotfile = False
|
||||||
filepath = None
|
filepath = None
|
||||||
while not gotfile:
|
while not gotfile:
|
||||||
|
@ -68,9 +98,11 @@ def openTest():
|
||||||
if getExtension(filepath) == '.tst':
|
if getExtension(filepath) == '.tst':
|
||||||
gotfile = True
|
gotfile = True
|
||||||
else:
|
else:
|
||||||
messagebox.showinfo("CHYBA: nerozeznany soubor", "Omlovame se ale soubory tupu '%s' nepodporujeme, podporujeme pouze soubory typu '.tst'" % (getExtension(filepath)))
|
messagebox.showinfo("ERROR: unrecognized file", "We are sorry but files with the '%s' appendix are not supported, we support only '.tst' files." % (getExtension(filepath)))
|
||||||
test = list(formatTest(filepath))
|
test = list(formatTest(filepath))
|
||||||
newQuestion()
|
newQuestion()
|
||||||
|
currentScore.set('Score: %s' % score)
|
||||||
|
highScore.set('High score: %d' % test[4])
|
||||||
|
|
||||||
|
|
||||||
def makeMenu(root):
|
def makeMenu(root):
|
||||||
|
@ -78,7 +110,7 @@ def makeMenu(root):
|
||||||
root.config(menu=menu)
|
root.config(menu=menu)
|
||||||
|
|
||||||
menu.add_command(label='Open', command=openTest)
|
menu.add_command(label='Open', command=openTest)
|
||||||
menu.add_command(label='Switch sides', command=None)
|
menu.add_command(label='Switch sides', command=swapSides)
|
||||||
|
|
||||||
return menu
|
return menu
|
||||||
|
|
||||||
|
@ -86,13 +118,13 @@ def makeMenu(root):
|
||||||
def makeRoot():
|
def makeRoot():
|
||||||
root = Tk()
|
root = Tk()
|
||||||
root.geometry('500x400')
|
root.geometry('500x400')
|
||||||
root.title('Vyzkousej me')
|
root.title('Test Me')
|
||||||
root.configure(bg="gray")
|
root.configure(bg="gray")
|
||||||
return root
|
return root
|
||||||
|
|
||||||
|
|
||||||
root = makeRoot()
|
root = makeRoot()
|
||||||
menu = makeMenu(root)
|
filepath = 'programfiles/default.tst'
|
||||||
test = list(formatTest('programfiles/default.tst'))
|
test = list(formatTest('programfiles/default.tst'))
|
||||||
questionPlace = 0
|
questionPlace = 0
|
||||||
score = 0
|
score = 0
|
||||||
|
@ -102,26 +134,32 @@ highScore = StringVar()
|
||||||
question = StringVar()
|
question = StringVar()
|
||||||
timeMultiplier = StringVar()
|
timeMultiplier = StringVar()
|
||||||
|
|
||||||
|
anotherSpacingLabel = Label(bg='gray', padx=5)
|
||||||
currentScoreLabel = Label(root, textvariable=currentScore, bg='gray')
|
currentScoreLabel = Label(root, textvariable=currentScore, bg='gray')
|
||||||
highScoreLabel = Label(root, textvariable=highScore, bg='gray')
|
highScoreLabel = Label(root, textvariable=highScore, bg='gray')
|
||||||
questionLabel = Label(root, textvariable=question)
|
questionLabel = Label(root, textvariable=question, width=30)
|
||||||
answerEntry = Entry(root)
|
spacingLabel = Label(bg='gray', padx=10)
|
||||||
|
answerEntry = Entry(root, width=30)
|
||||||
answerButton = Button(root, text='submit', command=submitAnswer)
|
answerButton = Button(root, text='submit', command=submitAnswer)
|
||||||
timeMultiplierLabel = Label(root, textvariable=timeMultiplier, bg='gray')
|
timeMultiplierLabel = Label(root, textvariable=timeMultiplier, bg='gray')
|
||||||
|
|
||||||
currentScoreLabel.grid(row=0, column=0, columnspan=2, sticky=W)
|
anotherSpacingLabel.grid(row=0, column=0)
|
||||||
highScoreLabel.grid(row=0, column=2, columnspan=2, sticky=E)
|
currentScoreLabel.grid(row=0, column=1, columnspan=2, sticky=W)
|
||||||
questionLabel.grid(row=1, column=1, sticky=W)
|
highScoreLabel.grid(row=0, column=4, columnspan=2, sticky=E)
|
||||||
answerEntry.grid(row=1, column=2, sticky=E)
|
questionLabel.grid(row=1, column=2, sticky=W)
|
||||||
answerButton.grid(row=1, column=3, sticky=W)
|
spacingLabel.grid(row=1, column=3)
|
||||||
timeMultiplierLabel.grid(row=2, column=0, columnspan=4)
|
answerEntry.grid(row=1, column=4, sticky=E)
|
||||||
|
answerButton.grid(row=1, column=5, sticky=W)
|
||||||
|
timeMultiplierLabel.grid(row=2, column=1, columnspan=5)
|
||||||
|
|
||||||
currentScore.set('Score: %s' %(score))
|
currentScore.set('Score: %s' %(score))
|
||||||
highScore.set('High score: %s' %(test[4]))
|
highScore.set('High score: %d' %(test[4]))
|
||||||
question.set('question will appear here')
|
question.set('question will appear here')
|
||||||
timeMultiplier.set('Time multiplier is: 0')
|
timeMultiplier.set('Time multiplier is: 0')
|
||||||
|
|
||||||
root.protocol("WM_DELETE_WINDOW", on_closing)
|
root.protocol("WM_DELETE_WINDOW", on_closing)
|
||||||
|
answerEntry.bind('<Return>', submitAnswer)
|
||||||
|
|
||||||
|
menu = makeMenu(root)
|
||||||
|
|
||||||
root.mainloop()
|
root.mainloop()
|
||||||
|
|
Loading…
Reference in a new issue