【问题标题】:pyTelegramBotAPI is there another way for adding the markup width to a list of buttons?pyTelegramBotAPI 是否有另一种将标记宽度添加到按钮列表的方法?
【发布时间】:2021-08-10 20:08:14
【问题描述】:

标题几乎是我需要的,但我会解释为什么我需要它。 我正在使用for循环,然后在里面,我有一个将按钮添加到数组的循环,问题是我必须在底部制作一个单独的按钮,没有循环,因此,我搜索并找到了方法:

buttons = []
def gen_markup():
    markup = InlineKeyboardMarkup()
    markup.row_width = 1
    for x, y in zip(name, conexion):
        buttons.append(InlineKeyboardButton(x, url=y))
    buttons.append(InlineKeyboardButton("Añadir Botón", callback_data="add_btn"))
    reply_markup = InlineKeyboardMarkup([buttons])
    return reply_markup

所以,一切正常,只是标记的宽度不起作用,我理解,因为我返回的是 reply_markup 变量,而不是 ma​​rkup一。 所以基本上我需要解决这个问题,如果你找到另一种方式,我当然愿意接受,我只是把那个放在标题中,因为这是我唯一能想到的。 谢谢

【问题讨论】:

    标签: python py-telegram-bot-api


    【解决方案1】:

    试试这段代码,剩下的就看你的python技能了

    def gen_markup():
        markup = InlineKeyboardMarkup(row_width=1)
        markup.add(*[InlineKeyboardButton(x, url=y)) for x, y in zip(name, conexion)])
        markup.add(InlineKeyboardButton("Añadir Botón", callback_data="add_btn"))
        
        return reply_markup
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-01-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多