如何在kivy Label/python中返回多个if/else语句(Kivy标签无法返回多个if/else语句) [英] How to return multiple if/else statements in kivy Label/python (Kivy label fail to return more than one if/else statement)

查看:105
本文介绍了如何在kivy Label/python中返回多个if/else语句(Kivy标签无法返回多个if/else语句)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用if/else简单逻辑在python和kivy中编写一个简单的测验应用程序,但我无法获得想要的东西.问题在于,kivy标签仅返回我的代码的if/else块.同一函数中的其余if/else语句被忽略.我尝试调试它,但找不到问题.请帮忙!! 如果我的问题看起来很愚蠢,请耐心等待,因为我是kivy和python的新手. 提前致谢!!!!代码的python部分如下:

I'm writing a simple quiz app in python and kivy using the if/else simple logic but I can't get what I want. The problem is that the kivy label is returning only one if/else block of my code. The rest if/else statments in the same function was ignored. I tried to debug it but I couldn't find out the problem. Please Help!! Bear with me if my question look stupid as I'm new to kivy and python. Thanks in advance!!!! The python part of the code is below:

def MyTest(self, *args, **kwargs):

    ids =[self.ids.my_label, self.ids.my_textinput]

        t = self.ids.my_textinput
        if t.text == "Hello":
            self.ids.my_label.text = "The text is\n Hello world"
        else:
            self.ids.my_label.text = "No answer\n wrong!!\n\n"

        if t.text == "is":     
            self.ids.my_label.text = "Correct!!!"
        else:
            self.ids.my_label.text = "Failed!!" 
    return      

推荐答案

使用类似方法

    t = self.ids.my_textinput  ## can't tell what this does
    if t.text == "Hello":
        self.ids.my_label.text = "The text is\n Hello world"
    elif t.text == "is":     
        self.ids.my_label.text = "Correct!!!"
    else:
        self.ids.my_label.text = "Whatever you want if every compare failed" 

这篇关于如何在kivy Label/python中返回多个if/else语句(Kivy标签无法返回多个if/else语句)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆