Skip to content

Instantly share code, notes, and snippets.

@CharlyWargnier
Last active April 9, 2024 08:02
Show Gist options
  • Save CharlyWargnier/c96f0f9fda2f7e24511a4ba81ea7f7e8 to your computer and use it in GitHub Desktop.
Save CharlyWargnier/c96f0f9fda2f7e24511a4ba81ea7f7e8 to your computer and use it in GitHub Desktop.
A Streamlit app for navigating through inspirational quotes with "Next" and "Previous" buttons.
import streamlit as st
if 'count' not in st.session_state:
st.session_state.count = 0
if 'quotes' not in st.session_state:
st.session_state.quotes = [
"Life is what happens when you're busy making other plans. — John Lennon",
"Get busy living or get busy dying. — Stephen King",
"You only live once, but if you do it right, once is enough. — Mae West",
"Many of life’s failures are people who did not realize how close they were to success when they gave up. — Thomas A. Edison",
"If you want to live a happy life, tie it to a goal, not to people or things. — Albert Einstein"
]
def display_quote():
quote = st.session_state.quotes[st.session_state.count]
st.write(quote)
def next_quote():
if st.session_state.count + 1 >= len(st.session_state.quotes):
st.session_state.count = 0
else:
st.session_state.count += 1
def previous_quote():
if st.session_state.count > 0:
st.session_state.count -= 1
st.title("Inspirational Quotes")
display_quote()
col1, col2 = st.columns(2)
with col1:
if st.button("⏮️ Previous", on_click=previous_quote):
pass
with col2:
if st.button("Next ⏭️", on_click=next_quote):
pass
@allanj
Copy link

allanj commented Jan 24, 2024

Thanks for doing this. This is really helpful

@Jamaludiin
Copy link

Helpful, thanks.

@insightbuilder
Copy link

Worked like a charm. Thanks mate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment