我有一个标签和一个文本输入,我想通过 .py 文件上的变量更改它的文本属性。 代码如下:
这是 .kv
<DefinicaoDeSaidas>:
BoxLayout:
orientation:'vertical'
BoxLayout:
orientation:'vertical'
padding: 0,20,20,50
Image:
source:'exemplo.png'
Label:
text:'Escolha as missoes para a saida'
font_size:40
TextInput:
id: ti
这是.py
class DefinicaoDeSaidas(Screen):
#get the values and everything
#transformate a variable ('name') onto the ti.text property
您可以通过github仓库查看所有代码:https://github.com/Enzodtz/FLL-Artificial-Inteligence
最佳答案
不要在 .py 中使用 id,因为它通常会导致出现类似 foo_object.ids.ti
的代码,相反,您可以将其公开为属性:
<DefinicaoDeSaidas>:
ti: ti # <---
BoxLayout:
orientation:'vertical'
BoxLayout:
orientation:'vertical'
padding: 0,20,20,50
Image:
source:'exemplo.png'
Label:
text:'Escolha as missoes para a saida'
font_size:40
TextInput:
id: ti
然后您可以通过任何方法使用 self 进行访问:
class DefinicaoDeSaidas(Screen):
# ...
def foo_function(self, another_arguments):
v = self.ti.text # get text
self.ti.text = u # update text
关于python - 如何通过.py文件上的id修改kivy小部件属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54029533/