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