MCPcopy Create free account
hub / github.com/eternnoir/pyTelegramBotAPI / InlineKeyboardMarkup

Class InlineKeyboardMarkup

telebot/types.py:3119–3227  ·  view source on GitHub ↗

This object represents an inline keyboard that appears right next to the message it belongs to. .. note:: It is recommended to use :meth:`telebot.util.quick_markup` instead. .. code-block:: python3 :caption: Example of a custom keyboard with buttons. from tele

Source from the content-addressed store, hash-verified

3117
3118
3119class InlineKeyboardMarkup(Dictionaryable, JsonSerializable, JsonDeserializable):
3120 """
3121 This object represents an inline keyboard that appears right next to the message it belongs to.
3122
3123 .. note::
3124 It is recommended to use :meth:`telebot.util.quick_markup` instead.
3125
3126 .. code-block:: python3
3127 :caption: Example of a custom keyboard with buttons.
3128
3129 from telebot.util import quick_markup
3130
3131 markup = quick_markup({
3132 'Twitter': {'url': 'https://twitter.com'},
3133 'Facebook': {'url': 'https://facebook.com'},
3134 'Back': {'callback_data': 'whatever'}
3135 }, row_width=2)
3136 # returns an InlineKeyboardMarkup with two buttons in a row, one leading to Twitter, the other to facebook
3137 # and a back button below
3138
3139 Telegram Documentation: https://core.telegram.org/bots/api#inlinekeyboardmarkup
3140
3141 :param keyboard: :obj:`list` of button rows, each represented by an :obj:`list` of
3142 :class:`telebot.types.InlineKeyboardButton` objects
3143 :type keyboard: :obj:`list` of :obj:`list` of :class:`telebot.types.InlineKeyboardButton`
3144
3145 :param row_width: number of :class:`telebot.types.InlineKeyboardButton` objects on each row
3146 :type row_width: :obj:`int`
3147
3148 :return: Instance of the class
3149 :rtype: :class:`telebot.types.InlineKeyboardMarkup`
3150 """
3151 max_row_keys = 8
3152
3153 @classmethod
3154 def de_json(cls, json_string):
3155 if json_string is None: return None
3156 obj = cls.check_json(json_string, dict_copy=False)
3157 keyboard = [[InlineKeyboardButton.de_json(button) for button in row] for row in obj['inline_keyboard']]
3158 return cls(keyboard = keyboard)
3159
3160 def __init__(self, keyboard=None, row_width=3):
3161 if row_width > self.max_row_keys:
3162 # Todo: Will be replaced with Exception in future releases
3163 logger.error('Telegram does not support inline keyboard row width over %d.' % self.max_row_keys)
3164 row_width = self.max_row_keys
3165
3166 self.row_width: int = row_width
3167 self.keyboard: List[List[InlineKeyboardButton]] = keyboard or []
3168
3169 def add(self, *args, row_width=None) -> 'InlineKeyboardMarkup':
3170 """
3171 This method adds buttons to the keyboard without exceeding row_width.
3172
3173 E.g. InlineKeyboardMarkup.add("A", "B", "C") yields the json result:
3174 {keyboard: [["A"], ["B"], ["C"]]}
3175 when row_width is set to 1.
3176 When row_width is set to 2, the result:

Callers 14

newmemberFunction · 0.90
startFunction · 0.90
gen_markupFunction · 0.90
languages_keyboardFunction · 0.90
clicker_keyboardFunction · 0.90
languages_keyboardFunction · 0.90
clicker_keyboardFunction · 0.90
generate_calendar_daysFunction · 0.90
generate_calendar_monthsFunction · 0.90
startFunction · 0.90
languages_keyboardFunction · 0.90
clicker_keyboardFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…