gpt4 book ai didi

Python - 如何使用多个参数在 Kivy 上绑定(bind) Button on_press

转载 作者:行者123 更新时间:2023-11-28 19:23:11 27 4
gpt4 key购买 nike

我读了thisthat标签。我有函数回调错误,标签有 NoneType。

class Root(FloatLayout):

def callback( self, label, instance, *args ):
## Try to pass Button.text to the label,
## but type(label) is a NoneType
label.text = instance.text # here
print(label, type(label))


def load_content(self):
content = self.content

for but in range(65, 67):
content.add_widget(Button( text=chr(but),
on_press = partial(self.callback, self.lbl),
font_size=20 ))

content = ObjectProperty(None)
lbl = ObjectProperty(None)

最佳答案

查看您作为标签值传递的内容。

你有没有得到类似这样的堆栈:

def my_callback(label, instance):            
label.text = instance.text

my_callback(None, None)

Traceback (most recent call last):
File "***/vars.py", line 34, in <module>
my_callback(None, None)
File "***/vars.py", line 32, in my_callback
label.text = instance.text
AttributeError: 'NoneType' object has no attribute 'text'

如果是这样,您的源标签是 NoneType,您将需要对其进行追踪。

关于Python - 如何使用多个参数在 Kivy 上绑定(bind) Button on_press,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19796866/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com