import telebot from telebot.types import InlineKeyboardButton, InlineKeyboardMarkup markup = InlineKeyboardMarkup(row_width=2) markup.add(InlineKeyboardButton("Button 1"), InlineKeyboardButton("Button 2")) markup.add(InlineKeyboardButton("Button 3"), InlineKeyboardButton("Button 4")) bot.send_message(chat_id, "Choose an option:", reply_markup=markup)
import telebot from telebot.types import InlineKeyboardButton, InlineKeyboardMarkup markup = InlineKeyboardMarkup() row = [] for i in range(8): row.append(InlineKeyboardButton(f"Button {i+1}")) if len(row) == 4: markup.add(*row) row = [] markup.add(*row) bot.send_message(chat_id, "Choose an option:", reply_markup=markup)In this example, we create an inline keyboard markup with an unspecified `row_width`. We create eight buttons in a loop and add them to the markup in rows of four using the `add` method. If the current row has fewer than four buttons, we wait until the next loop iteration to add the row. This allows us to dynamically adjust the row width based on the number of buttons we want to display. The `telebot.types` package is a part of the `python-telegram-bot` library, which provides a Python interface to the Telegram Bot API.