# Keyboard shortcut assigned to a push button

**URL:** <https://discourse.slicer.org/t/keyboard-shortcut-assigned-to-a-push-button/32650>\
**Category:** Development\
**Tags:** module, gui\
**Created:** [November 7, 2023, 8:50pm UTC](https://discourse.slicer.org/t/keyboard-shortcut-assigned-to-a-push-button/32650 "2023-11-07T20:50:26Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![laurentletg](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/laurentletg/32/10051_2.png) [@laurentletg](https://discourse.slicer.org/u/laurentletg)\
**Post date:** [November 7, 2023, 8:50pm UTC](https://discourse.slicer.org/t/keyboard-shortcut-assigned-to-a-push-button/32650/1 "2023-11-07T20:50:26Z")

</div>

Hello,

I’ve seen examples of how to assign keyboard shortcuts in the forum and the [script repository.](https://slicer.readthedocs.io/en/latest/developer_guide/script_repository.html#customize-keyboard-shortcuts) I was wondering if there is a quick way to simply assign a keyboard shortcut to an existing push button (without necessarily calling a function). The idea is to use the shortcut as an alternative to clicking the push button.

For example, in Qt for Python it is possible to assign a shortcut to a button using button.setShortcut(). Unless I made an error somewhere, I was not able to replicate this in a custom slicer module.

```auto
# Example with PySide6
from PySide6.QtGui import QKeySequence

###...other lines here...
# Set the shortcut to Ctrl+B (for example)
self.button.setShortcut(QKeySequence("Ctrl+B"))

```

Thanks!
