mirror of
https://github.com/python-telegram-bot/python-telegram-bot.git
synced 2024-11-24 16:17:37 +01:00
Updated Code snippets (markdown)
parent
b5245cf4a1
commit
eefc24b1e5
1 changed files with 4 additions and 1 deletions
|
@ -606,12 +606,15 @@ 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
|
||||||
|
from typing import Union, List
|
||||||
|
from telegram import InlineKeyboardButton
|
||||||
|
|
||||||
def build_menu(
|
def build_menu(
|
||||||
buttons: List[InlineKeyboardButton],
|
buttons: List[InlineKeyboardButton],
|
||||||
n_cols: int,
|
n_cols: int,
|
||||||
header_buttons: Union[InlineKeyboardButton, List[InlineKeyboardButton]]=None,
|
header_buttons: Union[InlineKeyboardButton, List[InlineKeyboardButton]]=None,
|
||||||
footer_buttons: Union[InlineKeyboardButton, List[InlineKeyboardButton]]=None
|
footer_buttons: Union[InlineKeyboardButton, List[InlineKeyboardButton]]=None
|
||||||
):
|
) -> List[List[InlineKeyboardButton]]:
|
||||||
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 if isinstance(header_buttons, list) else [header_buttons])
|
menu.insert(0, header_buttons if isinstance(header_buttons, list) else [header_buttons])
|
||||||
|
|
Loading…
Reference in a new issue