S
S
Studentka19962021-07-03 10:15:28
Python
Studentka1996, 2021-07-03 10:15:28

How to display buttons in multiple rows?

I can not display buttons in 2 rows (post-request). Please help.

I output it like this:

# {{1строк_1кнопка,1строка_2кнопка},{2строка_1кнопка}}
def ls_keybs_Order(id_order, date_order, pay_url, summa, mind):
     ls = []
     ls.append({'text': "\U0001f4b3 Оплатить", 'url': pay_url[0]})
     # ls.append({'text': "Оплачен?", 'callback_data': f'Проверить_{id_order}'})
     if mind == 0:
          ls.append({'text': "Оплачен?", 'callback_data': f'Проверить_{id_order}', 'text': 'Напомнить', 'callback_data': f'{id_order}_Напом_{date_order}_Напом_{summa}'})
     ls.append({'text': '❌ Отменить', 'callback_data': f'ОтменаЗаказа_{id_order}'})
     return ls


60e014a7daf52238978426.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Mikhail Krostelev, 2021-07-03
@Studentka1996

You should have a list of rows. Each row is a separate list.

just add [ ] in the right places

def ls_keybs_Order(id_order, date_order, pay_url, summa, mind):
     ls = []
     ls.append([{'text': "\U0001f4b3 Оплатить", 'url': pay_url[0]}]) # добавили не кнопку, а список из одной кнопки
     # ls.append({'text': "Оплачен?", 'callback_data': f'Проверить_{id_order}'})
     if mind == 0:
          ls.append([{'text': "Оплачен?", 'callback_data': f'Проверить_{id_order}'}, {'text': 'Напомнить', 'callback_data': f'{id_order}_Напом_{date_order}_Напом_{summa}'}]) # аналогично первому ряду
     ls.append([{'text': '❌ Отменить', 'callback_data': f'ОтменаЗаказа_{id_order}'}]) # еще один ряд
     return ls

The question remains why don't you use telebot, aiogram or some other library for all this.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question