0

Brython 如何像 Jquery/Javascript 在继续执行之前那样等待图像加载?

在上面的 Brython 代码错误列表中永远不会附加,因为img.bind('load', on_load)不会阻止执行。如何在继续之前阻止执行?

随意提供建议或替代方法来处理 Brython 中的等待/阻塞。

error = []
img = html.IMG(src=blob)
document <= img
def on_load(event):
   if img.height*img.width > 2:
       errors.append(f"Image dimensions are too large.")
       print(errors) # The above error does indeed exist in errors.
img.bind('load', on_load)
if errors:
    print(errors) # errors is empty because this was declared as img.bind was running
4

1 回答 1

0

有没有你打电话的地方img.load(),或者这应该自动发生?

如果不是,则预期当前行为,因为on_load()已声明并绑定到img,但永远不会调用img'load()函数。因此on_load()从未真正运行过。

于 2022-01-03T15:39:41.020 回答