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

Function quick_markup

telebot/util.py:421–468  ·  view source on GitHub ↗

Returns a reply markup from a dict in this format: {'text': kwargs} This is useful to avoid always typing 'btn1 = InlineKeyboardButton(...)' 'btn2 = InlineKeyboardButton(...)' Example: .. code-block:: python3 :caption: Using quick_markup: from telebot.util im

(values: Dict[str, Dict[str, Any]], row_width: int = 2)

Source from the content-addressed store, hash-verified

419
420
421def quick_markup(values: Dict[str, Dict[str, Any]], row_width: int = 2) -> types.InlineKeyboardMarkup:
422 """
423 Returns a reply markup from a dict in this format: {'text': kwargs}
424 This is useful to avoid always typing 'btn1 = InlineKeyboardButton(...)' 'btn2 = InlineKeyboardButton(...)'
425
426 Example:
427
428 .. code-block:: python3
429 :caption: Using quick_markup:
430
431 from telebot.util import quick_markup
432
433 markup = quick_markup({
434 'Twitter': {'url': 'https://twitter.com'},
435 'Facebook': {'url': 'https://facebook.com'},
436 'Back': {'callback_data': 'whatever'}
437 }, row_width=2)
438 # returns an InlineKeyboardMarkup with two buttons in a row, one leading to Twitter, the other to facebook
439 # and a back button below
440
441 # kwargs can be:
442 {
443 'url': None,
444 'callback_data': None,
445 'switch_inline_query': None,
446 'switch_inline_query_current_chat': None,
447 'callback_game': None,
448 'pay': None,
449 'login_url': None,
450 'web_app': None
451 }
452
453 :param values: a dict containing all buttons to create in this format: {text: kwargs} {str:}
454 :type values: :obj:`dict`
455
456 :param row_width: number of :class:`telebot.types.InlineKeyboardButton` objects on each row
457 :type row_width: :obj:`int`
458
459 :return: InlineKeyboardMarkup
460 :rtype: :obj:`types.InlineKeyboardMarkup`
461 """
462 markup = types.InlineKeyboardMarkup(row_width=row_width)
463 buttons = [
464 types.InlineKeyboardButton(text=text, **kwargs)
465 for text, kwargs in values.items()
466 ]
467 markup.add(*buttons)
468 return markup
469
470
471# CREDITS TO http://stackoverflow.com/questions/12317940#answer-12320352

Callers

nothing calls this directly

Calls 1

addMethod · 0.95

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…