【问题标题】:Brython wait for image to load, ajax call, or other async functions to complete before continuing executionBrython 等待图像加载、ajax 调用或其他异步函数完成,然后再继续执行
【发布时间】:2021-03-05 11:49:57
【问题描述】:

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

【问题讨论】:

    标签: javascript python asynchronous brython


    【解决方案1】:

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

    如果不是,那么当前行为是预期的,因为 on_load() 已声明并绑定到 img,但从未调用 imgload() 函数。因此on_load() 从未真正运行过。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-10-31
      • 1970-01-01
      • 2016-10-29
      • 1970-01-01
      • 1970-01-01
      • 2011-02-12
      • 1970-01-01
      相关资源
      最近更新 更多