Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3b50924
commit 18d9f43
Showing
6 changed files
with
162 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
What is my favourite colour?, red, yellow, green, blue, red | ||
What year is it?, 2000, 2018, 2017, 2020, 2018 | ||
What month is it?, October, February, April, May, April |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import sys | ||
sys.path.append("../../") | ||
from appJar import gui | ||
|
||
def launcher(btn): | ||
print(btn) | ||
|
||
with gui("Quiz Demo") as app: | ||
app.buttons(["Quiz", "Scores"], launcher) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import sys | ||
sys.path.append("../../") | ||
from appJar import gui | ||
|
||
def launcher(btn): | ||
app.showSubWindow(btn) | ||
|
||
with gui("Quiz Demo") as app: | ||
app.buttons(["Quiz", "Scores"], launcher) | ||
|
||
with app.subWindow("Quiz", modal=True): | ||
app.label("Quiz") | ||
|
||
with app.subWindow("Scores", modal=True): | ||
app.label("Scores") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import sys | ||
sys.path.append("../../") | ||
from appJar import gui | ||
|
||
# make the question array | ||
questions = [] | ||
with open("questions.txt") as f: | ||
for line in f: | ||
parts = line.split(",") | ||
q = {} | ||
q["question"] = parts[0] | ||
q["options"] = parts[1:-1] | ||
q["answer"] = parts[-1].strip() | ||
questions.append(q) | ||
|
||
def launcher(btn): | ||
app.showSubWindow(btn) | ||
|
||
def check(): | ||
app.nextFrame("Questions") | ||
|
||
with gui("Quiz Demo") as app: | ||
app.buttons(["Quiz", "Scores"], launcher) | ||
|
||
with app.subWindow("Quiz", modal=True): | ||
with app.frameStack("Questions", start=0): | ||
for pos, q in enumerate(questions): | ||
with app.frame(): | ||
with app.labelFrame("Question " + str(pos + 1)): | ||
app.label(q["question"]) | ||
for o in q["options"]: | ||
app.radio(str(pos), o) | ||
app.button("SUBMIT", check) | ||
|
||
with app.subWindow("Scores", modal=True): | ||
app.label("Scores") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import sys | ||
sys.path.append("../../") | ||
from appJar import gui | ||
|
||
# make the question array | ||
questions = [] | ||
with open("questions.txt") as f: | ||
for line in f: | ||
parts = line.split(",") | ||
q = {} | ||
q["question"] = parts[0] | ||
q["options"] = parts[1:-1] | ||
q["answer"] = parts[-1].strip() | ||
questions.append(q) | ||
|
||
def launcher(btn): | ||
app.showSubWindow(btn) | ||
|
||
def check(): | ||
qNum = app.getCurrentFrame("Questions") | ||
choice = app.radio(str(qNum)) | ||
answer = questions[qNum]["answer"] | ||
|
||
if choice == answer: | ||
app.infoBox("Correct", "You got it right") | ||
else: | ||
app.errorBox("Wrong", "You got it wrong") | ||
|
||
app.nextFrame("Questions") | ||
|
||
with gui("Quiz Demo") as app: | ||
app.buttons(["Quiz", "Scores"], launcher) | ||
|
||
with app.subWindow("Quiz", modal=True): | ||
with app.frameStack("Questions", start=0): | ||
for pos, q in enumerate(questions): | ||
with app.frame(): | ||
with app.labelFrame("Question " + str(pos + 1)): | ||
app.label(q["question"]) | ||
for o in q["options"]: | ||
app.radio(str(pos), o) | ||
app.button("SUBMIT", check) | ||
|
||
with app.subWindow("Scores", modal=True): | ||
app.label("Scores") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import sys | ||
sys.path.append("../../") | ||
from appJar import gui | ||
|
||
# make the question array | ||
questions = [] | ||
with open("questions.txt") as f: | ||
for line in f: | ||
parts = line.split(",") | ||
q = {} | ||
q["question"] = parts[0] | ||
q["options"] = parts[1:-1] | ||
q["answer"] = parts[-1].strip() | ||
questions.append(q) | ||
|
||
score = 0 | ||
|
||
def showScore(): | ||
app.label("score", "Score: " + str(score) + "/" + str(len(questions))) | ||
|
||
def launcher(btn): | ||
app.showSubWindow(btn) | ||
|
||
def check(): | ||
global score | ||
qNum = app.getCurrentFrame("Questions") | ||
choice = app.radio(str(qNum)) | ||
answer = questions[qNum]["answer"] | ||
|
||
if choice.strip() == answer.strip(): | ||
app.infoBox("Correct", "You got it right") | ||
score += 1 | ||
showScore() | ||
else: | ||
app.errorBox("Wrong", "You got it wrong") | ||
|
||
app.nextFrame("Questions") | ||
|
||
with gui("Quiz Demo") as app: | ||
app.buttons(["Quiz", "Scores"], launcher) | ||
|
||
with app.subWindow("Quiz", modal=True): | ||
with app.frameStack("Questions", start=0): | ||
for pos, q in enumerate(questions): | ||
with app.frame(): | ||
with app.labelFrame("Question " + str(pos + 1)): | ||
app.label(q["question"]) | ||
for o in q["options"]: | ||
app.radio(str(pos), o) | ||
showScore() | ||
app.button("SUBMIT", check) | ||
|
||
with app.subWindow("Scores", modal=True): | ||
app.label("Scores") |