【发布时间】:2020-11-19 21:59:52
【问题描述】:
我只想从我的 Second Class 的文本输入中提取一个数值到我的 Home Class,然后能够在函数中处理它。我想我在这里很难掌握父子关系和语法。
请帮忙...
Python 文件:
class Home(Screen):
#Generic function
def test(self):
#grab numbers from text input here and be able to use the numeric value using ids
#distance=..? I think normally it's self.root.distance.text
print("distance text input variable here")
pass
class Second(Screen):
pass
class WindowManager(ScreenManager):
pass
class HelpMe(App):
def build(self):
kv = Builder.load_file("help.kv")
self.Home=Home()
return kv
if __name__ == "__main__":
HelpMe().run()
kivy 文件:
WindowManager:
Home:
Second:
<Home>:
name:"Home"
GridLayout:
cols:1
Button:
text:"Go"
on_release:
app.root.current="Second"
root.manager.transition.direction="left"
<Second>:
name:"Second"
distance:distance
GridLayout:
cols:1
TextInput:
id:distance
input_filter:"int"
Button:
text:"Back"
#Initiate test code so I can work with values
on_release:
app.Home.test()
app.root.current="Home"
root.manager.transition.direction="right"
【问题讨论】:
标签: python class kivy textinput