我正在尝试使用Kivy
创建一个简单的脚本:
def __init__(self):
super(ProvaLayout, self).__init__()
self.cols = 2
self.Labell = Label(text="-------------")
self.add_widget(self.Labell)
self.btn = Button(text="caio")
self.add_widget(self.btn)
def callback(self, pos, instance):
self.Labell=Label(text="caio")
self.btn.bind(on_pressed = callback)
但是,上述内容不会更改labell
的文字。
答案 0 :(得分:0)
更正后的版本。评论中描述了错误。
def __init__(self):
super(ProvaLayout, self).__init__()
self.cols = 2
self.Labell = Label(text="-------------")
self.add_widget(self.Labell)
self.btn = Button(text="caio")
self.add_widget(self.btn)
def callback(instance): # single argument without self (it's a local function inside a method)
self.Labell.text="caio" # changing text property of existing self.Label instead of creating a new object
self.btn.bind(on_press = callback) # you should use on_press, not on_pressed