π―Β Β Keyboard to URL
Submitted by Arnaud Miribel
Summary
Create bindings so that hitting a key on your keyboard opens an URL in a new tab!
Functions
keyboard_to_url
Map a keyboard key to open a new tab with a given URL.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key |
str
|
Key to trigger (example 'k'). Defaults to None. |
None
|
key_code |
int
|
If key doesn't work, try hard-coding the key_code instead. Defaults to None. |
None
|
url |
str
|
Opens the input URL in new tab. Defaults to None. |
None
|
Source code in src/streamlit_extras/keyboard_url/__init__.py
Import:
- You should add this to the top of your .py file
Examples
example
def example():
# Main function
keyboard_to_url(key="S", url="https://www.github.com/streamlit/streamlit")
load_key_css()
st.write(
f"""Now hit {key("S", False)} on your keyboard...!""",
unsafe_allow_html=True,
)