Streamlit keyboard shortcuts for your buttons.
Project description
Streamlit Shortcuts
Streamlit Shortcuts allows you to easily add keyboard shortcuts to your Streamlit buttons.
Installation
pip install streamlit-shortcuts
Example
⭐ NEW! thanks to @quantum-ernest
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")
🥱 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".
Keys
- 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
Contributing
Contributions are welcome! If you have suggestions for improvements or bug fixes, please feel free to make a pull request or open an issue.
Contributors
@toolittlecakes - Added 'Meta' modifier
@quantum-ernest - Improved usage ergonomics
@taylor-ennen - Fixed usage flow
of code
Credits
Solution seen on: https://github.com/streamlit/streamlit/issues/1291
https://gist.github.com/brunomsantiago/e0ab366fc0dbc092c1a5946b30caa9a0
@brunomsantiago
@TomJohnH
And wrapped for comfier usage.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for streamlit-shortcuts-0.1.3.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 35fa426cc3babc56ec7e6ecb721e273fd00e8964bcf371f36e10867bfd860534 |
|
MD5 | 2071f10c3de0b3e8ec993101a1d34920 |
|
BLAKE2b-256 | 62def210c798f80ba1b19fdcc21983a3c2eeadcc9dde7ed258d6de60bf083981 |
Hashes for streamlit_shortcuts-0.1.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 81370aadc1f6b01fce89458707d7e41ed61fca9ba152a29aaab7e0735dde97bd |
|
MD5 | e8c17251b93555799a24751f9963ac9c |
|
BLAKE2b-256 | 1ecbed0847c63d477f731e4f08f9599cffd0083a3ec7d20c4da67e2128aedd27 |