C
C
char9062021-02-09 01:00:31
Python
char906, 2021-02-09 01:00:31

How to change the row_width of each button separately?

Good day!

markup = types.InlineKeyboardMarkup(row_width=1)

            item1 = types.InlineKeyboardButton("кнопка 1", callback_data='1')
            item2 = types.InlineKeyboardButton("кнопка 2", callback_data='2')
            item3 = types.InlineKeyboardButton("кнопка 3", callback_data='3')
            item4 = types.InlineKeyboardButton("кнопка 4", callback_data='4')
            item5 = types.InlineKeyboardButton("кнопка 5", callback_data='5')
            item6 = types.InlineKeyboardButton("кнопка 6", callback_data='6')
            item7 = types.InlineKeyboardButton("кнопка 7", callback_data='7')

            markup.add(item1, item2, item3, item4, item5, item6, item7)


I am writing this code and I have all the buttons in one line, how can I make row_width different for each button, that is, row_width=1 for buttons 1..5 and row_width=2 for buttons 6-7?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
soremix, 2021-02-09
@char906

row_width is not designed for this. It automatically divides buttons into groups according to the given length.
Use the method row(...), any number of arguments is passed to it, which will make up one row
https://github.com/eternnoir/pyTelegramBotAPI/blob...

buttons = [item1, item2, item3, item4, item5, item6, item7]

for button in buttons[:5]:
    markup.row(button)

markup.row(item6, item7)

You can probably do something prettier, but oh well

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question