How could I create a popup on my page that asks the user if they are over 15 years old, it would contain two buttons where the user would either confirm their age as over 15 or under 15. However, the function of this would be that if the user clicked “under”, they would not get access to the page and vice versa.
Hi
See this thread
Thank you @Oscar1,
i saw this discussion however i did not figure out how to make something i would love to get out of it
Hello @jozi,
You can show a preliminary screen (acting as a “popup”) asking for the user’s age confirmation before displaying the main content.
import streamlit as st
if 'age_verified' not in st.session_state:
st.session_state.age_verified = False
if 'is_over_15' not in st.session_state:
st.session_state.is_over_15 = None
def verify_age(over_15):
st.session_state.age_verified = True
st.session_state.is_over_15 = over_15
if not st.session_state.age_verified:
st.header("Age Verification")
st.write("Are you over 15 years old?")
col1, col2 = st.columns(2)
with col1:
# Button for users over 15
if st.button("Yes, I'm over 15"):
verify_age(True)
with col2:
# Button for users under 15
if st.button("No, I'm under 15"):
verify_age(False)
# If age has been verified and user is over 15, show the main content
elif st.session_state.age_verified and st.session_state.is_over_15:
st.header("Welcome to the page!")
# Your main app content goes here
# If the user is under 15, display a message denying access
elif st.session_state.age_verified and not st.session_state.is_over_15:
st.error("Sorry, you must be over 15 years old to access this page.")
Kind Regards,
Sahir Maharaj
Data Scientist | AI Engineer
P.S. Lets connect on LinkedIn!
➤ Want me to build your solution? Lets chat about how I can assist!
➤ Join my Medium community of 30k readers! Sharing my knowledge about data science and AI
➤ Website: https://sahirmaharaj.com
➤ Email: sahir@sahirmaharaj.com
➤ 100+ FREE Power BI Themes: Download Now
I appreciate your help, however I am using multipage (from st_pages import show_pages, Page
), so this won’t work, however thank you very much for the idea!
Could you create a minimal reprodicble code?
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.