How to return multiple if/else statements in kivy Label/python (Kivy label fail to return more than one if/else statements)
How to return multiple if/else statements in kivy Label/python (Kivy label fail to return more than one if/else statement)
我正在 python 和 kivy 中使用 if/else 简单逻辑编写一个简单的测验应用程序,但我无法得到我想要的。问题是 kivy 标签只返回我代码的一个 if/else 块。同一函数中的其余 if/else 语句被忽略。我试图调试它,但我找不到问题所在。请帮忙!!
如果我的问题看起来很愚蠢,请耐心等待,因为我是 kivy 和 python 的新手。
提前致谢!!!! python 部分代码如下:
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"
而不是一堆if/elif,使用字典http://www.tutorialspoint.com/python/python_dictionary.htm
t_dict= {"Hello":"The text is\n Hello world",
"is":"Correct!!!"}
t = self.ids.my_textinput
if t.text in t_dict:
self.ids.my_label.text = t_dict[t.text]
else:
self.ids.my_label.text = "Whatever you want if every compare failed"
我正在 python 和 kivy 中使用 if/else 简单逻辑编写一个简单的测验应用程序,但我无法得到我想要的。问题是 kivy 标签只返回我代码的一个 if/else 块。同一函数中的其余 if/else 语句被忽略。我试图调试它,但我找不到问题所在。请帮忙!! 如果我的问题看起来很愚蠢,请耐心等待,因为我是 kivy 和 python 的新手。 提前致谢!!!! python 部分代码如下:
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"
而不是一堆if/elif,使用字典http://www.tutorialspoint.com/python/python_dictionary.htm
t_dict= {"Hello":"The text is\n Hello world",
"is":"Correct!!!"}
t = self.ids.my_textinput
if t.text in t_dict:
self.ids.my_label.text = t_dict[t.text]
else:
self.ids.my_label.text = "Whatever you want if every compare failed"