The st.dialog doc not show how to stop the x or esc, I hope can use my button not x or esc.
Because I set a st.session_state[“key”] to make data_editor can reset.
There is any method can solve it?
Because I set a st.session_state[“key”] to make data_editor can reset.
There is any method can solve it?
You can refer to the following methods to make adjustments, where the method of hiding buttons is the CSS style design in ‘st. html’.
import streamlit as st
st.html(
'''
<style>
div[aria-label="dialog"]>button[aria-label="Close"] {
display: none;
}
</style>
'''
)
@st.experimental_dialog(title='title')
def test_dialog():
st.write('Hello Streamlit')
if st.button(label='open_dialog', key='test_dialog', type='primary'):
test_dialog()
Thank!!! This help me a lot.
I also want to know how to prevent the dialog from closing when the user clicks on the grey background(purple section).
I can’t find name of the grey background(purple section).
There is also an open request around customizing the behavior around the X to close. The discussion includes ignoring the X and basically configuring the dialog to be dismissible or not. Feel free to vote or add to the conversation:
Since the dialog can be closed if you press “esc”, I used “pyautogui”, a python library, to handle pressing the “esc” button after the button click. This worked for me:
This sounded like a cool idea but pyautogui doesn’t run from the streamlit run since mouse is not available on the server, the package cannot be loaded to the client. Did it work for you?
2024-09-07 09:33:42.321 Uncaught app exception
Traceback (most recent call last):
File "/workspace/voting-app/cx/venv/lib/python3.12/site-packages/streamlit/runtime/scriptrunner/exec_code.py", line 88, in exec_func_with_error_handling
result = func()
^^^^^^
File "/workspace/voting-app/cx/venv/lib/python3.12/site-packages/streamlit/runtime/scriptrunner/script_runner.py", line 590, in code_to_exec
exec(code, module.__dict__)
File "/workspace/voting-app/cx/app/app.py", line 51, in <module>
pg.run()
File "/workspace/voting-app/cx/venv/lib/python3.12/site-packages/streamlit/navigation/page.py", line 291, in run
exec(code, module.__dict__)
File "/workspace/voting-app/cx/app/ui/channel_list.py", line 5, in <module>
import pyautogui
File "/workspace/voting-app/cx/venv/lib/python3.12/site-packages/pyautogui/__init__.py", line 246, in <module>
import mouseinfo
File "/workspace/voting-app/cx/venv/lib/python3.12/site-packages/mouseinfo/__init__.py", line 223, in <module>
_display = Display(os.environ['DISPLAY'])
~~~~~~~~~~^^^^^^^^^^^
File "<frozen os>", line 714, in __getitem__
KeyError: 'DISPLAY'
You’re right, it worked when I run it on windows, but once I migrated to the server I got this error. I used the “keyboard” library (keyboard · PyPI) as a workaround but encountered the same issue (os.environ[‘DISPLAY’]) with other libraries. So it’s better to fix that problem first to avoid any issues(still can’t fix it ). But You can still try the keyboard library as a quick fix.
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.