Updated Code snippets (markdown)

Bibo-Joshi 2021-05-05 14:19:25 +02:00
parent e205d21236
commit b5245cf4a1

@ -606,15 +606,17 @@ All possible actions are documented [here](https://core.telegram.org/bots/api#se
Often times you will find yourself in need for a menu with dynamic content. Use the following `build_menu` method to create a button layout with `n_cols` columns out of a list of `buttons`. Often times you will find yourself in need for a menu with dynamic content. Use the following `build_menu` method to create a button layout with `n_cols` columns out of a list of `buttons`.
```python ```python
def build_menu(buttons, def build_menu(
n_cols, buttons: List[InlineKeyboardButton],
header_buttons=None, n_cols: int,
footer_buttons=None): header_buttons: Union[InlineKeyboardButton, List[InlineKeyboardButton]]=None,
footer_buttons: Union[InlineKeyboardButton, List[InlineKeyboardButton]]=None
):
menu = [buttons[i:i + n_cols] for i in range(0, len(buttons), n_cols)] menu = [buttons[i:i + n_cols] for i in range(0, len(buttons), n_cols)]
if header_buttons: if header_buttons:
menu.insert(0, [header_buttons]) menu.insert(0, header_buttons if isinstance(header_buttons, list) else [header_buttons])
if footer_buttons: if footer_buttons:
menu.append([footer_buttons]) menu.append(footer_buttons if isinstance(footer_buttons, list) else [footer_buttons])
return menu return menu
``` ```