S
S
SashaN692020-12-10 20:29:13
Python
SashaN69, 2020-12-10 20:29:13

Is it possible to add a button cycle in a telegram bot?

Is it possible to display a KeyboardButton to the user of the bot using a loop.
Let's say there is a list And you need to somehow display the buttons to the user with each element of the list. l = ['Яблоко', 'Груша'] #список з названиями

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2020-12-10
@SashaN69

Of course, here's an example. I use the construction for callback, because the list is of variable length.

l = ['Яблоко', 'Груша']
keyboard = types.InlineKeyboardMarkup()
backbutton = types.InlineKeyboardButton(text="Back", callback_data="MainMenu")
button_list = [types.InlineKeyboardButton(text=x, callback_data=x) for x in l]
keyboard.add(*button_list, backbutton)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question