【发布时间】:2018-02-18 13:01:00
【问题描述】:
我花了一天的时间处理来自How to access id/widget of different class from a kivy file (.kv)? 的代码,我已经将它与最简单的代码配对,因为我想做的是使用 Kivy 的时钟功能为我更改文本,而不是单击按钮。
尽我所能理解更改文本的代码应该在程序的第 38 行,但我尝试的所有代码都停止执行,因为它无法访问文本来更改它。时钟功能在提供的代码中工作。
我已将按钮按下处于活动状态,但我想更改文本的是时钟代码。我想知道是否有人知道解决方案。
提前致谢。
....布拉德....
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.boxlayout import BoxLayout
from kivy.clock import Clock
from kivy.properties import ObjectProperty
Builder.load_string("""
<SingleScreen>:
id: single_screen
orientation: 'vertical'
Button:
text: "You Can Change Me By Button Press Here But I Really Want To Be Changed By Kivy's Clock Function"
on_release: root.rooted()
Change_Label:
id: gb
<Change_Label>:
_python_access: ChangeLabel
Label:
id: ChangeLabel
text: "I'm Gonna Change."
""")
class SingleScreen(BoxLayout):
def rooted(self):
self.ids.gb._python_access.text = "I Changed It By Clicking!. But That's Not What I Wanted To Program!"
class Change_Label(BoxLayout):
_python_access = ObjectProperty(None)
class OnlyScreen(App):
def build(self):
Clock.schedule_interval(self.Callback_Clock, 3)
return SingleScreen()
def Callback_Clock(self, dt):
print "Hello, world! I'm the clock working...."
# What code goes here that will change the text via Kivy's clock instead of using the button?
if __name__ == '__main__':
OnlyScreen().run()
【问题讨论】:
标签: kivy kivy-language