T
T
TheMergus2019-12-29 14:19:19
Python
TheMergus, 2019-12-29 14:19:19

How to place inline buttons horizontally?

There is a python code that displays inline buttons with information from the database (sqlite3):

keyboard = types.InlineKeyboardMarkup(row_width=2)
for .... in .... :
        q.execute("SELECT name FROM categors where id = " + str(bb))
        r = q.fetchone()
        keyboard.add(types.InlineKeyboardButton(text=str(r[0]),callback_data='categ_'+str(bb)))
      bot.send_message(message.chat.id, "Выбери категорию: ", reply_markup=keyboard)

Buttons are displayed vertically, you need horizontal
keyboard = types.InlineKeyboardMarkup(row_width=2) does not help

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
SHADRIN, 2020-12-30
@shadrin_ss

knb = types.InlineKeyboardMarkup()
knb.add(*[types.InlineKeyboardButton(text=name, callback_data=name) for name in['Кнопка 1','Кнопка 2', 'Кнопка 3']])

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question