liveBook · Manning

User interface component

As explained in Python How-To

A widget is a self-contained user-interface component that displays information or provides an interaction.

A widget is a user-interface element that displays information or lets someone interact with an app. In Streamlit, you specify a widget’s type and configuration; the framework handles the layout. When a user changes an input, Streamlit reruns the script from top to bottom. Session state can help address cases where that behavior is inconvenient. section 14.4.1 section 14.4.1

In a task manager, widgets can collect sorting and filtering choices, organize task content into columns, and let users open a task’s details. A button click can trigger an action such as displaying the selected task. section 14.4.5

Figure 14.6 The available widgets in the streamlit framework. The six categories are Clickable (buttons), Single or Multiple Choice, Numeric Data, Textual Data, Multimedia, and Date and Time.
CH14_F06_Cui

Browse Streamlit widget categories, from buttons and choices to text, multimedia, and date-and-time inputs. section 14.4.1

Listing 14.11 Showing the tasks in the web app
def show_tasks():
    filter_params = session[sorting_params_key]
    if filter_params[TaskierFilterKey.SORTING_KEY.value] is not None:
        reading_params = get_reading_params(filter_params)
        tasks = Task.load_tasks(**reading_params)
        sorting_key = sorting_keys[filter_params[
 TaskierFilterKey.SORTING_KEY.value]]
        should_reverse = filter_params[
 TaskierFilterKey.SORTING_ORDER.value] == sorting_orders[1]
        tasks.sort(key=lambda x: getattr(x, sorting_key), 
 reverse=should_reverse)
    else:
        tasks = Task.load_tasks()                      #1
   
    for task in tasks:
        col1, col2 = st.columns([3, 1])                #2
        col1.write(str(task))
        col2.button("View Detail", key=task.task_id, 
 on_click=wants_task_detail, args=(task,))
        st.write(f"Status: {task.status.name.title()}")
        st.markdown("___")                             #3

See a task-list example that uses columns and a button to display task information and open details. section 14.4.5

How Python How-To covers it

How deep it goes
Explains widget configuration, layout delegation, and script reruns, but leaves basic widget instructions to external documentation.
Examples
Shows buttons, filtering controls, task-list columns, and task-detail interactions in a task-management app.
What you can do after
Apply Streamlit widgets to display tasks, collect filtering choices, and trigger task-detail views.
How it connects
Connects widgets to Streamlit, session state, user input, and sorting and filtering.

Also explained in

Compare how 2 books explain user interface component →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Python How-To. The section links point to the parts of the book it draws on.