C
C
Cyril2020-04-23 18:10:47
Python
Cyril, 2020-04-23 18:10:47

Method to populate InlineKeyboardMarkup in a loop?

I'm trying to create a bot on the python-telegram-bot library, I can't create buttons in a loop:

if data == "7":
        markup = InlineKeyboardMarkup(resize_keyboard=True)
        for answer in answers:
            button = InlineKeyboardButton(text=answer, callback_data=answer)
            markap.row(button)
        update.message.reply_text("Ваш вопрос:\n" + text_question[0], reply_markup=markup)

The markap.row(button ) method from another library just tried to execute. Please tell me the method for this library.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
C
Cyril, 2020-04-24
@Pus1st

answers = ["A", "B", "C"]
    elif data == "7":
        for answer in answers:
            keys.append(InlineKeyboardButton(text=answer, callback_data=answer))
        print(answers)
        markup = InlineKeyboardMarkup([keys], resize_keyboard=True)
        query.message.reply_text("Ваш вопрос:\n" + text_question[0], reply_markup=markup)

As I understand it, this library does not have a separate method (or I just did not find it), I implemented it by adding it to a separate list.

M
Mikhail Krostelev, 2020-04-23
@twistfire92

mark u p = InlineKeyboardMarkup(resize_keyboard=True)
for answer in answers:
button = InlineKeyboardButton(text=answer, callback_data=answer)
mark a p.row(button)
update.message.reply_text("Your question:\n" + text_question [0], reply_markup=markup)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question