(python-telegram-bot) 如何使用 button_row 调整按钮大小

(python-telegram-bot) How to resize button using button_row

我正在尝试在我的电报机器人中调整 KeyboardButton 的大小。我正在为我的机器人使用 Python-Telegram-Bot 包装器。我找到了 button_row 选项 (docs),但我不明白应该将它粘贴到哪里。

代码:

def start(update, context):

    custom_keyboard = [['top-left', 'top-right'],
                      ['bottom-left', 'bottom-right']]
    reply_markup = ReplyKeyboardMarkup(custom_keyboard)
    update.message.reply_text(text="Custom Keyboard Test", reply_markup=reply_markup)

button_rowReplyKeyboardMarkup 接受的第一个位置参数。在你的例子中,你提供 custom_keyboard 作为这个参数;这是正确的。

您可能正在寻找的是 resize_keyboard 参数,根据您链接的那个页面,它接受一个布尔值:

Requests clients to resize the keyboard vertically for optimal fit (e.g., make the keyboard smaller if there are just two rows of buttons). Defaults to false, in which case the custom keyboard is always of the same height as the app’s standard keyboard. Defaults to False

我明白这可能不是你的意思,但如果你想要这种行为,请将代码中的这一行更新为:

reply_markup = ReplyKeyboardMarkup(custom_keyboard, resize_keyboard=True)