-
如题,用popup加表单验证功能无法实现,因为是验证是同步执行,没机会响应用户点击popup上按钮的结果。 |
Beta Was this translation helpful? Give feedback.
Answered by
wang0618
Oct 3, 2021
Replies: 1 comment 1 reply
-
可以使用锁机制来将popup变成同步的: from pywebio import start_server
from pywebio.output import *
import threading
def confirm(title, content=None, timeout=None):
"""Show a confirm model.
:param str title: Model title.
:param list/put_xxx() content: Model content.
:param None/float timeout:
:return: Return `True` when the "CONFIRM" button is clicked, return `False` when the "CANCEL" button is clicked,
return `None` when a timeout is given and the operation times out.
"""
if not isinstance(content, list):
content = [content]
event = threading.Event()
result = None
def onclick(val):
nonlocal result
result = val
event.set()
content.append(put_buttons([
{'label': 'CONFIRM', 'value': True},
{'label': 'CANCEL', 'value': False, 'color': 'danger'},
], onclick=onclick))
popup(title=title, content=content, closable=False)
event.wait(timeout=timeout)
close_popup()
return result
def main():
res = confirm('Confirm', 'You have 5 seconds to make s choice', timeout=5)
put_text("Your choice is:", res)
start_server(main, port=8080, debug=True) |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
yichangle
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
可以使用锁机制来将popup变成同步的: