gpt4 book ai didi

Streamlit - Using selected text as input on button click(Streamlit-单击按钮时使用所选文本作为输入)

转载 作者:bug小助手 更新时间:2023-10-22 15:58:59 28 4
gpt4 key购买 nike



Is there a way in Streamlit to:

Streamlight中是否有方法:



  • Select text in a text area

    选择文本区域中的文本



  • Click a button to have the selected text be used an an input to a backend function

    单击按钮可将所选文本用作后端功能的输入




So this would take only the text excerpt selected by the user and send that as a function input and not the entire text in the text area.

因此,这将只获取用户选择的文本摘录,并将其作为函数输入发送,而不是文本区域中的整个文本。


Researched and haven't found a way to do this. Thanks.

已进行了研究,但尚未找到实现此目的的方法。谢谢


enter image description here


更多回答
优秀答案推荐

Here is a simple example with a callback associated to a button, on which you give a text input by a user as argument:

下面是一个简单的例子,其中回调与一个按钮关联,在该按钮上,您可以将用户输入的文本作为参数:


import streamlit as st

st.session_state["user_input"] = st.text_input(label="enter text")


def my_callback(text_to_display):
st.text(str(text_to_display))


st.button("display text", on_click=my_callback, args=(st.session_state["user_input"],))

It gives that when running:
enter image description here

它在运行时给出:


I used these text input doc and button doc.

我使用了这些文本输入文档和按钮文档。


更多回答

Thanks, I meant something a little different. Edited and added an image to make it clearer above.

谢谢,我的意思有点不同。编辑并添加了一个图像,使其在上面更清晰。

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