I suggest creating a kivy ListProperty that holds your answers, a string property to hold your question.
Here is a start. This displays the problems, and will create new problems. It does not do anything with the answers.
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.boxlayout import BoxLayout
from kivy.properties import StringProperty, ListProperty
from random import randint
kv = """
<QuizBox>:
orientation: 'vertical'
Label:
text: root.problem
font_size: 20
BoxLayout:
Button:
text: str(root.answers[0])
Button:
text: str(root.answers[1])
Button:
text: str(root.answers[2])
Button:
text: 'Next'
on_release: root.create_problem()
QuizBox:
"""
class QuizBox(BoxLayout):
problem = StringProperty('Start')
answers = ListProperty([0] * 3)
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.a = 0
self.b = 0
self.create_problem()
def create_problem(self):
self.a = randint(1,10)
self.b = randint(1,10)
self.problem = f'{self.a} + {self.b} = ?'
self.answers[0] = self.a + self.b # add the answer...
for i in range(1,3):
x = randint(1,20)
while x in self.answers: # make sure the answers are all unique
x = randint(1,20)
self.answers[i] = x
self.answers.sort() # sort so the correct answer is not always in the same spot.
class QuizApp(App):
def build(self):
return Builder.load_string(kv)
QuizApp().run()
--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/834d5363-d644-40e3-bca5-511310c4d2bdo%40googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-...@googlegroups.com.