Здравствуйте! Пытаюсь создать инлайн-кнопки в цикле, разбивая их на ряды по 8 штук в каждом. Сами кнопки создаются, но клавиатура выдает ошибку:
'list' object has no attribute 'to_dict'. Подозреваю, что неправильно полльзуюсь методом
keyboard.row(). Что я делаю не так?
def create_keyboard_details(buttons:list):
print('\r\nКнопки:', buttons)
#return None
keyboard = types.InlineKeyboardMarkup()
btns_in_row = 8
keyboard.row_width = btns_in_row
btn_count = len(buttons)
row_count = btn_count//btns_in_row
surplus = btn_count - row_count * btns_in_row
print('\r\nКнопки в цикле:')
for i in range(row_count):
btn_list = []
for N in range(btns_in_row):
btn = types.InlineKeyboardButton(str(i * btns_in_row + N + 1), callback_data = 'pos_' + str(buttons[i * btns_in_row + N]))
btn_list.append(btn)
print(btn_list)
keyboard.row(btn_list)
btn_list = []
for i in range(surplus):
btn = types.InlineKeyboardButton(str(btn_count - surplus + i), callback_data = 'pos_' + str(buttons[btn_count - surplus + i]))
btn_list.append(btn)
print(btn_list)
keyboard.row(btn_list)
return keyboard
Результат в консоли:
Кнопки в цикле:
[<telebot.types.InlineKeyboardButton object at 0x00000199A13DDE50>, <telebot.types.InlineKeyboardButton object at 0x00000199A13DDEB0>, <telebot.types.InlineKeyboardButton object at 0x00000199A13DDEE0>, <telebot.types.InlineKeyboardButton object at 0x00000199A13DDF10>, <telebot.types.InlineKeyboardButton object at 0x00000199A13DDF40>, <telebot.types.InlineKeyboardButton object at 0x00000199A13DDF70>, <telebot.types.InlineKeyboardButton object at 0x00000199A13DDFA0>, <telebot.types.InlineKeyboardButton object at 0x00000199A13DDFD0>]
[<telebot.types.InlineKeyboardButton object at 0x00000199A1390610>, <telebot.types.InlineKeyboardButton object at 0x00000199A13906D0>, <telebot.types.InlineKeyboardButton object at 0x00000199A13908E0>, <telebot.types.InlineKeyboardButton object at 0x00000199A1390700>, <telebot.types.InlineKeyboardButton object at 0x00000199A1390760>, <telebot.types.InlineKeyboardButton object at 0x00000199A13908B0>, <telebot.types.InlineKeyboardButton object at 0x00000199A1390790>, <telebot.types.InlineKeyboardButton object at 0x00000199A13907C0>]
[<telebot.types.InlineKeyboardButton object at 0x00000199A13907F0>, <telebot.types.InlineKeyboardButton object at 0x00000199A1390820>, <telebot.types.InlineKeyboardButton object at 0x00000199A1390850>, <telebot.types.InlineKeyboardButton object at 0x00000199A1390880>, <telebot.types.InlineKeyboardButton object at 0x00000199A1390730>, <telebot.types.InlineKeyboardButton object at 0x00000199A1390910>, <telebot.types.InlineKeyboardButton object at 0x00000199A1390A00>, <telebot.types.InlineKeyboardButton object at 0x00000199A1390940>]
'list' object has no attribute 'to_dict'