为什么textinput值没有用这个代码更新?我需要捕捉用户在单击按钮时键入的值,但不管看起来如何,我只能获得默认文本。在
这是python 3.4.3上的一个可运行示例:
# -*- coding: utf-8 -*-
import kivy
kivy.require("1.9.1")
from kivy.app import App
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.button import Button
from kivy.uix.textinput import TextInput
from functools import partial
class TestApp(App):
def check(self, texto, *args):
print(texto)
def build(self):
layout = FloatLayout()
txtinput = TextInput(background_color=(1,1,1,1),
font_size=16,
size_hint=(None, None),
size=(200, 35),
pos_hint={"center_x":0.5, "bottom":0.8},
multiline=False,
text="write here...",
use_bubble=True)
boton = Button(size_hint=(None, None),
size=(150, 50),
pos_hint={"left":1, "bottom":1},
text="Check",
on_release=partial(self.check, txtinput.text))
layout.add_widget(txtinput)
layout.add_widget(boton)
return layout
if __name__ == "__main__":
TestApp().run()
我想要一个纯Python的答案,我不太喜欢使用kv文件。在
在创建
txtinput
之后,用with TextInput.bind()将check
方法绑定到您的txtinput
:输入值在相关代码段中可用。在
目前check方法是实例方法,我想它总是接受
App
的实例作为第一个属性,txtinput作为第二个属性,input text作为第三个属性。在要访问
^{pr2}$check
中的文本,方法签名应更新为该方法:相关问题 更多 >
编程相关推荐