【发布时间】:2020-05-13 23:25:09
【问题描述】:
with open("file.kv", encoding='utf-8') as f:
Builder.load_string(f.read())
class content(Screen):
pass
class resistor(Screen):
pass
sm = ScreenManager()
sm.add_widget(content())
sm.add_widget(resistor())
def printthecontentsofthetextinput():
do something
class MyApp(App):
def build(self):
return sm
这是我的 kv 文件:
<resistor>
name:"r"
Image:
source:"lamp1.jpg"
allow_stretch:True
keep_ratio:False
FloatLayout:
size:root.width,root.height
allow_stretch:False
keep_ratio:False
Label:
text:"R"
color:1,1,1,1
pos_hint:{"x":0.03,"y":0.23}
size_hint:0.1,0.05
TextInput:
id:rprim
focus:True
background_color:0.8,0.96,0.88,1
pos_hint:{"x":0.15,"y":0.23}
size_hint:0.1,0.05
Label:
text:"Ω"
color:1,1,1,1
pos_hint:{"x":0.28,"y":0.23}
size_hint:0.05,0.05
我正在尝试使用 id 访问文本输入:rprim
我试过 print(resistor().ids.rprim.text) 但即使我在 textinput 中写了一些东西,它总是返回空白
【问题讨论】:
标签: python user-interface kivy kivy-language