lundi 19 septembre 2022

How to display random questions in KV label or in a KV Layout

I am new in PY and KV and i am trying to make a quizz app . I learned how to generate random questions in PY and to be displayed in the IDE console but now i am trying to display them in a KV Layout and if the answer is the right one , a random question to be generated and now i am stuck at this step... and yep.. HEEELP PLEASE :(( !!


from kivy.app import App
from kivy.uix.screenmanager import Screen, ScreenManager

from kivy.config import Config
Config.set("graphics", "Resizable", "1")


class Q1(Screen):
    pass


# Random code

import random

def randomq():
    print("How many questions ?")
    numberOfProblems = input()
    numberOfProblems = int(numberOfProblems)

    if numberOfProblems > 3:
        print("You can answer only to 3 questions.")
        randomq()
    if numberOfProblems <= 0:
        print("Finish")
        exit(0)
    else:
        for questionsWanted in range(numberOfProblems):
            question1 = 1
            question2 = 2
            question3 = 3
            question4 = 4

            questionNumber = random.randint(1,2)

            if questionNumber == 1:
                question1Answer = input("What is color of grass ?")
                if question1Answer == "green":
                    print("Correct")
                else:
                    ("Not correct")

            if questionNumber == 2:
                question2Answer = input("What is a car ?")
                if question2Answer == "A car" or question2Answer == "car":
                    print("Correct")
                else:
                    ("Not correct")

randomq()



class ScreenManagement(ScreenManager):
    pass



class QuizApp(App):
    pass





QuizApp().run()

#:import random random

ScreenManagement:
    Q1:

<Q1>:
    FloatLayout:
        orientation: "vertical"

        Label:
            text: "Is the earth round ?"
            font_size: self.width/25
            pos_hint: {"x":0, "y":0.2}

        Button:
            text: "Yes"
            font_size: self.width/30
            size_hint: 0.5, 0.12
            pos_hint: {"x":0.25, "y":0.4}

        Button:
            text: "No"
            font_size: self.width/30
            size_hint: 0.5, 0.12
            pos_hint: {"x":0.25, "y":0.52}





Aucun commentaire:

Enregistrer un commentaire