File size: 1,202 Bytes
d2da12e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6da69a5
d2da12e
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import streamlit as st
import os

def load_data():
    if os.path.exists('data.txt'):
        with open('data.txt', 'r') as file:
            lines = file.readlines()
            nombre = lines[0].strip().split(': ')[1]
            fecha = lines[1].strip().split(': ')[1]
        return nombre, fecha
    return '', ''

def save_data(nombre, fecha):
    with open('data.txt', 'w') as file:
        file.write(f'nombre: {nombre}\n')
        file.write(f'fecha: {fecha}\n')

def main():
    st.title('Data Entry Popup')

    if 'show_popup' not in st.session_state:
        st.session_state.show_popup = False

    if st.button('Open Popup'):
        st.session_state.show_popup = True

    if st.session_state.show_popup:
        st.write('### Enter Data')
        nombre, fecha = load_data()

        new_nombre = st.text_input('Nombre', value=nombre)
        new_fecha = st.text_input('Fecha', value=fecha)

        if st.button('Save'):
            save_data(new_nombre, new_fecha)
            st.success('Data saved successfully')
            st.session_state.show_popup = False

        if st.button('Cancel'):
            st.session_state.show_popup = False

if __name__ == "__main__":
    main()