當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Python Streamlit st.text_area用法及代碼示例

顯示多行文本輸入小部件。

函數簽名

st.text_area(label, value="", height=None, max_chars=None, key=None, help=None, on_change=None, args=None, kwargs=None, *, placeholder=None, disabled=False)
參數說明

label (str)

一個簡短的標簽,向用戶解釋此輸入的用途。

value (any)

此小部件首次呈現時的文本值。這將在內部強製轉換為 str 。

height (int or None)

以像素表示的 UI 元素的所需高度。如果沒有,則使用默認高度。

max_chars (int or None)

文本區域中允許的最大字符數。

key (str or int)

一個可選的字符串或整數,用作小部件的唯一鍵。如果省略,將根據其內容為小部件生成一個 key 。相同類型的多個小部件可能不共享相同的鍵。

help (str)

顯示在文本區域旁邊的可選工具提示。

on_change (callable)

當此 text_area 的值更改時調用的可選回調。

args (tuple)

傳遞給回調的可選參數元組。

kwargs (dict)

一個可選的 kwargs 字典傳遞給回調。

placeholder (str or None)

當文本區域為空時顯示的可選字符串。如果為 None,則不顯示任何文本。此參數隻能由關鍵字提供。

disabled (bool)

一個可選的布爾值,如果設置為 True,則禁用文本區域。默認值為假。此參數隻能由關鍵字提供。

返回說明

(str)

文本輸入小部件的當前值。

示例

txt = st.text_area('Text to analyze', '''
     It was the best of times, it was the worst of times, it was
     the age of wisdom, it was the age of foolishness, it was
     the epoch of belief, it was the epoch of incredulity, it
     was the season of Light, it was the season of Darkness, it
     was the spring of hope, it was the winter of despair, (...)
     ''')
st.write('Sentiment:', run_sentiment_analysis(txt))

相關用法


注:本文由純淨天空篩選整理自streamlit.io大神的英文原創作品 st.text_area。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。