当我使用 kivy.clock 时,为什么我的 Kivy 文本输入无法将值返回给 root
Why doesn't my Kivy Text input work in returning the value to root when I use kivy.clock
import kivy
from kivy.lang.builder import Builder
from kivy.app import App
from kivy.properties import StringProperty, ObjectProperty
from kivy.uix.widget import Widget
from kivy.clock import Clock
Builder.load_string('''
<apper>
input_val : input_t
BoxLayout:
size: root.size
Label:
id: label_t
text: root.texter
TextInput:
id: input_t
Button:
on_press : root.doer()
''')
class apper(Widget):
texter = StringProperty()
input_val = ObjectProperty(None)
run = 0
def doer(self, dt):
self.run+=1 # keep track of number of times this function ran
#self.texter = self.ids.input_t.text
print(self.ids.input_t.text, self.run) #prints an empty string for self.ids.input_t.text
self.texter = self.input_val.text
class runs(App):
def build(self):
Clock.schedule_interval(apper().doer, 1.0/2.0)
return apper()
runs().run()
#the code works when you remove the Clock statement and the second argument or apper.doer() and you have to press the button
#to rename the label
#how comes it doesnt work when you introduce the clock statement
#Note that I am new to kivy but not new to programming
当我使用按钮 运行 时,按下功能会返回来自文本输入的正确值,但使用时钟时它不起作用,任何人都可以提供帮助。
此外,当程序应该 运行 与时钟正确连接时,则不需要按钮,因为它每 0.5 秒用 TextInput 的文本更新标签。
有什么方法可以重写或修改代码,使 TextInput returns 成为一个值而不是空字符串。
把时钟移到你的纸上class:然后这样写
Clock.schedule_interval(self.doer, 1/2)
并像这样声明执行者:
def doer(self, *args):
随时查看我最近上传的教程
https://www.youtube.com/watch?v=DbX-CdVob6E&t=57s
import kivy
from kivy.lang.builder import Builder
from kivy.app import App
from kivy.properties import StringProperty, ObjectProperty
from kivy.uix.widget import Widget
from kivy.clock import Clock
Builder.load_string('''
<apper>
input_val : input_t
BoxLayout:
size: root.size
Label:
id: label_t
text: root.texter
TextInput:
id: input_t
Button:
on_press : root.doer()
''')
class apper(Widget):
texter = StringProperty()
input_val = ObjectProperty(None)
run = 0
def doer(self, dt):
self.run+=1 # keep track of number of times this function ran
#self.texter = self.ids.input_t.text
print(self.ids.input_t.text, self.run) #prints an empty string for self.ids.input_t.text
self.texter = self.input_val.text
class runs(App):
def build(self):
Clock.schedule_interval(apper().doer, 1.0/2.0)
return apper()
runs().run()
#the code works when you remove the Clock statement and the second argument or apper.doer() and you have to press the button
#to rename the label
#how comes it doesnt work when you introduce the clock statement
#Note that I am new to kivy but not new to programming
当我使用按钮 运行 时,按下功能会返回来自文本输入的正确值,但使用时钟时它不起作用,任何人都可以提供帮助。 此外,当程序应该 运行 与时钟正确连接时,则不需要按钮,因为它每 0.5 秒用 TextInput 的文本更新标签。 有什么方法可以重写或修改代码,使 TextInput returns 成为一个值而不是空字符串。
把时钟移到你的纸上class:然后这样写
Clock.schedule_interval(self.doer, 1/2)
并像这样声明执行者:
def doer(self, *args):
随时查看我最近上传的教程 https://www.youtube.com/watch?v=DbX-CdVob6E&t=57s