【发布时间】:2016-02-09 09:21:05
【问题描述】:
我正在尝试使用 kivy 制作一个应用程序,它将文本从 textinput 小部件传递到一个按钮小部件,这两个小部件都有不同的小部件树,我可以这样做吗,因为我似乎在文档中找不到任何关于这个。
我的python代码:
class Tes(App):
pass
class Text(TextInput):
pass
class Buton(Button):
def on_push(self, text):
print 'keep it up' + text
if __name__=='__main__':
Tes().run()
我的 Kivy 代码:
#:kivy 1.9.0
FloatLayout
canvas:
Color:
rgb: 0, 1, 0
Rectangle:
size: self.size
pos: self.pos
TextInput:
text: 'hi'
id: text
size_hint: (.5, .5)
pos_hint: {'top': .4, 'left': .4}
Text
Buton
<Text>
pos_hint: {'top': 1, 'right': 1}
size_hint: (.1, .1)
id: text
<Buton>
pos_hint: {'top': 1, 'left': 1}
size_hint: (.1, .1)
id: button
on_press: self.on_push(root.text)
【问题讨论】: