0
這是我t.py如何在Lable中設置文本,來自__init__中初始化的變量?
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
class Simple(BoxLayout):
def __init__(self, **kwargs):
super(Simple, self).__init__(**kwargs)
# THIS IS SIMLE EXAMPLE, IN PRACTICE I AM READING VALUE FROM TEXT FILE
self.sometext = 'Hello from Init.'
def set_text(self):
return self.sometext # error: 'Simple' object has no attribute 'sometext'
#return "Hello World from Simple(BoxLayout)" # this is working
class TApp(App):
def build(self):
return Simple()
TApp().run()
我t.kv
<Simple>:
Label:
#text: 'Hello World' # THIS IS WORKING
text: root.set_text()
所以這是行不通的 什麼需要做得到它的工作?
我希望它是更多鈔票...
感謝
你有沒有測試這個簡單的例子,在那裏你直接設置'self.sometext'?問題可能出現在您從文件中檢索值的代碼中。 – jonrsharpe
不明白。你能提供代碼樣本嗎? – WebOrCode