Kivy-Python如何从同一个根目录中获取更新的按钮文本?
所以我有一个很长的测试列表,我试图一个接一个地拉动每个测试,但由于某种原因,在kivy拉动第一个测试后,我无法让它拉动第二个问题,即使变量已更新为不同的信息 解析Kivy-Python如何从同一个根目录中获取更新的按钮文本?,python,xml,xpath,kivy,kivy-language,Python,Xml,Xpath,Kivy,Kivy Language,所以我有一个很长的测试列表,我试图一个接一个地拉动每个测试,但由于某种原因,在kivy拉动第一个测试后,我无法让它拉动第二个问题,即使变量已更新为不同的信息 解析 tree = ET.parse('data.xml') root = tree.getroot() path = tree.xpath("/quizbook/quiz/@chapter") d = 1 index = str(d) forgetti = tree.xpath("/quizbook/
tree = ET.parse('data.xml')
root = tree.getroot()
path = tree.xpath("/quizbook/quiz/@chapter")
d = 1
index = str(d)
forgetti = tree.xpath("/quizbook/quiz[1]/question[{}]/query/text()".format(d))
spaghetti = forgetti.pop()
noodles = spaghetti
supapath = tree.xpath("/quizbook/quiz[1]/question[{}]/answer[1]/@correct".format(d))
spapath = tree.xpath("/quizbook/quiz[1]/question[{}]/answer[2]/@correct".format(d))
gear = tree.xpath("/quizbook/quiz[1]/question[{}]/answer[3]/@correct".format(d))
fly = tree.xpath("/quizbook/quiz[1]/question[{}]/answer[4]/@correct".format(d))
snow= tree.xpath("/quizbook/quiz[1]/question[{}]/answer[1]/text()".format(d))
sno= tree.xpath("/quizbook/quiz[1]/question[{}]/answer[2]/text()".format(d))
sn= tree.xpath("/quizbook/quiz[1]/question[{}]/answer[3]/text()".format(d))
snew= tree.xpath("/quizbook/quiz[1]/question[{}]/answer[4]/text()".format(d))
heat = snow.pop()
hea = sno.pop()
he = sn.pop()
her= snew.pop()
leaf = heat
lea = hea
le = he
leif = her
我的.kv按钮
if 0 == len(gear):
Builder.load_string("""
<TestScreen>:
Button:
text: root.spon
background_normal: "buttonc.png"
background_down: "buttonwrong.png"
size_hint: .40, .20
pos_hint:{ "y": .45,"x": .55}
""")
else:
Builder.load_string("""
<TestScreen>:
Button:
text: root.spon
background_normal: "buttonc.png"
background_down: "buttoncorrect.png"
size_hint: .40, .20
pos_hint:{ "y": .45,"x": .55}
""")
if 0 == len(fly):
Builder.load_string("""
<TestScreen>:
Button:
text: root.spo
background_normal: "buttond.png"
background_down: "buttonwrong.png"
size_hint: .40, .20
pos_hint:{ "y": .20,"x": .55}
""")
else:
Builder.load_string("""
<TestScreen>:
Button:
text: root.spo
background_normal: "buttond.png"
background_down: "buttoncorrect.png"
size_hint: .40, .20
pos_hint:{ "y": .20,"x": .55}
""")
Builder.load_string("""
<TestScreen>:
Label:
text: root.judge
color:0,150,60,1
font_size: dp(20)
size_hint: .30, .40
pos_hint:{"y": .63, "x": .15}
Button:
text: "next"
size_hint: .10, .10
pos_hint:{"y": .05, "x": .10}
on_press:
root.btn_clk()
root.manager.current = 'test2'
""")
if 0 == len(supapath):
Builder.load_string("""
<TestScreen>:
Button:
text: root.sponge
background_normal: "buttona.png"
background_down: "buttonwrong.png"
size_hint: .40, .20
pos_hint:{"left":.90, "y": .45,"x": .05}
""")
else:
Builder.load_string("""
<TestScreen>:
Button:
text: root.sponge
background_normal: "buttona.png"
background_down: "buttoncorrect.png"
size_hint: .40, .20
pos_hint:{"left":.90, "y": .45,"x": .05}
""")
if 0 == len(spapath):
Builder.load_string("""
<TestScreen>:
Button:
text: root.spong
background_normal: "buttonb.png"
background_down: "buttonwrong.png"
size_hint: .40, .20
pos_hint:{"left":.90, "y": .20,"x": .05}
""")
else:
Builder.load_string("""
<TestScreen>:
Button:
text: root.spong
background_normal: "buttonb.png"
background_down: "buttoncorrect.png"
size_hint: .40, .20
pos_hint:{"left":.90, "y": .20,"x": .05}
目前我的d值每次都在上升。我已经做了一个打印(海绵),以确保变量正在更改。当点击按钮时,它会更新,但文本似乎没有改变文本停留在第一个问题所说的内容以及第一个问题的答案上,没有任何改变。我的目标是让它在每次问题和答案集随D值变化时都发生变化
class TestScreen(Screen,Button):
sponge = leaf
spong = lea
spon = le
spo = leif
judge = noodles
def btn_clk(self, *args):
global d
d += 1