问题
I wish button1 to edit Label 'etykietka' when clicked, but i don't know how. Have you got some ideas?
class Zastepstwa (App):
def build(self):
lista=WebOps().getList()
layout = BoxLayout(orientation='vertical')
etykietka = Label(text='aa', font_size=10)
button1 = Button(text='aa')
button1.bind(callback)
layout.add_widget(etykietka)
layout.add_widget(button)
return layout
def callback (instance):
newLabelText='kkk'
#?
回答1:
you need to pass your label to callback, a nice way to do it is to use the partial function
from functools import partial
change callback signature for
def callback(label, instance, *args):
label.text='kkk'
then bind the callback like this
button1.bind(on_press=partial(callback, etykieta))
that should do it.
回答2:
Also, make sure you have the callback function indented and directly after the build function. Otherwise the callback function won be recognized in the bind statement.
来源:https://stackoverflow.com/questions/12339167/kivy-editing-label-when-button-clicked