Answer the question
In order to leave comments, you need to log in
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
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 questionAsk a Question
731 491 924 answers to any question