python - telepot 中的内联键盘样式

标签 python python-3.x telegram-bot telepot

我可以使用 Telepot 将内联键盘按钮放在多行上吗?
如果我能做到,我该怎么做?


我尝试通过这个示例来学习如何使用 InlineKeyboard,
但我没有找到有关 Telepot 中内联键盘的其他文档(官方文档除外)

import sys
import time
import telepot
from telepot.namedtuple import ReplyKeyboardMarkup, KeyboardButton


def on_chat_message(msg):
    content_type, chat_type, chat_id = telepot.glance(msg)
    print('Chat Message:', content_type, chat_type, chat_id)

    if content_type == 'text':
        if msg['text'] == '/key':
            bot.sendMessage(chat_id, 'testing custom keyboard',
                            reply_markup=ReplyKeyboardMarkup(
                                keyboard=[
                                    [KeyboardButton(text="btn1"), KeyboardButton(text="btn2"),KeyboardButton(text="btn3"), KeyboardButton(text="btn4")]
                                ]
                            ))


TOKEN = sys.argv[1]  # get token from command-line

bot = telepot.Bot(TOKEN)
print('Listening ...')
bot.message_loop({'chat': on_chat_message}, run_forever=True)

我需要帮助

谢谢

最佳答案

解决了!
示例代码:

bot.sendMessage(chat_id, 'testing custom keyboard',reply_markup = InlineKeyboardMarkup(inline_keyboard=[
                                    [InlineKeyboardButton(text="btn1",callback_data='I have Nothing To do'), InlineKeyboardButton(text="btn2",callback_data='0'),InlineKeyboardButton(text="btn3",callback_data='0'), InlineKeyboardButton(text="btn4",callback_data='0')],
                                    [InlineKeyboardButton(text="btn1",callback_data='yep')]
                                ]
                            ))

结果:
keyboard result

关于python - telepot 中的内联键盘样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57749268/

相关文章:

python - 将 Python 二元运算符视为值

python - 如何检查json对象是否为数组

python-3.x - 以 Python 作为基础镜像的 CentOS

c# - 如何在 C# 中隐藏 ReplyKeyboardMarkup?

python-3.x - 如何处理 python 电报 bot 中的回调查询

python - 为 Pyspark 中的每一行计算列中不同的子字符串出现次数?

python - 从件号获取位置id的算法

python - 使用python在django中将任何格式(flv、3gp、MXF等)的视频转换为MP4

python - 将图形嵌入 GUI(Qtdesigner 和 Pyside)

telegram - 使用 multipart/form-data 和 allowed_updates 设置 Telegram bot webhook