Streamlit Shortcuts allows you to easily add keyboard shortcuts to your Streamlit buttons.
pip install streamlit-shortcuts
import streamlit as st
import streamlit_shortcuts
def delete_callback():
st.write("DELETED!")
streamlit_shortcuts.button("delete", on_click=delete_callback, shortcut="Ctrl+Shift+X", hint=True)
⭐ New in v0.1.8: Shortcut hint by @quantum-ernest
![featuring the new feature by @quantum-ernest `hint`](https://private-user-images.githubusercontent.com/90320947/358654137-e7f68879-331e-4850-83d5-90b3d1697db7.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjQ1NTc0MDcsIm5iZiI6MTcyNDU1NzEwNywicGF0aCI6Ii85MDMyMDk0Ny8zNTg2NTQxMzctZTdmNjg4NzktMzMxZS00ODUwLTgzZDUtOTBiM2QxNjk3ZGI3LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA4MjUlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwODI1VDAzMzgyN1omWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTBlZWRkMTcyZmQ2MzQ3NGQzZDM2ZWM3M2Y1NmZkNTk2NTk5MGYyZThjNzFjMzhmMmY5NWM5MWMwMmNhNDY1NTImWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.RylZBdviA_Wd4YNgliHDLj_wNOOdCIXiQwQsUJ8nSoI)
⭐ NEW in v0.1.5: Support for args and kwargs
import streamlit as st
import streamlit_shortcuts
def delete_callback(item_id, user="anonymous"):
st.write(f"Item {item_id} DELETED by {user}!")
streamlit_shortcuts.button(
"Delete",
shortcut="Ctrl+Shift+X",
on_click=delete_callback,
hint=True,
args=(42,),
kwargs={"user": "admin"},
type="primary"
)
This creates a primary Streamlit button labeled "Delete" with the shortcut "Ctrl+Shift+X".
When clicked (or activated via shortcut), it calls delete_callback(42, user="admin")
.
🥱 Old
import streamlit as st
from streamlit_shortcuts import add_keyboard_shortcuts
def delete_callback():
st.write("DELETED!")
st.button("delete", on_click=delete_callback)
add_keyboard_shortcuts({
'Ctrl+Shift+X': 'delete',
})
The 'Ctrl+Shift+X' combination will trigger "Another Button".
- Modifiers: 'Ctrl', 'Shift', 'Alt', 'Meta' ('Cmd' on Mac or 'Win' on Windows, thanks to @toolittlecakes)
- Common Keys: 'Enter', 'Escape', 'Space'
- Arrow Keys: 'ArrowLeft', 'ArrowRight', 'ArrowUp', 'ArrowDown'
Examples of Key Combinations:
- 'Ctrl+Enter'
- 'Shift+ArrowUp'
- 'Alt+Space'
For a complete list of key values, refer to: https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key/Key_Values
We use semantic versioning. The current version is stored in the VERSION
file in the root of the repository.
Contributions are welcome! If you have suggestions for improvements or bug fixes, please follow these steps:
- Fork the repository
- Create a new branch for your feature or bugfix
- Make your changes
- Add or update tests as necessary
- Update the
VERSION
file if your changes warrant a version bump - Submit a pull request
Please make sure to update tests as appropriate and adhere to the existing coding style.
To release a new version:
- Update the
VERSION
file with the new version number - Commit the change:
git commit -am "Bump version to X.Y.Z"
- Create a new tag:
git tag vX.Y.Z
- Push the changes and the tag:
git push && git push --tags
The GitHub Actions workflow will automatically create a new release and publish to PyPI.
- @toolittlecakes
- Added 'Meta' modifier
- @quantum-ernest
- Improved usage ergonomics
- Keyboard hints
- @taylor-ennen
- Fixed usage
flow
of code
- Fixed usage
Solution inspired by:
Special thanks to @brunomsantiago and @TomJohnH for their initial work on this concept.
Wrapped and extended for easier usage by the Streamlit Shortcuts team.