Answer the question
In order to leave comments, you need to log in
[[+content_image]]
Dynamic creation of variables (InlineKeyboard), right?
from aiogram.types import InlineKeyboardButton, InlineKeyboardMarkup
category_menu_list = [['1', 'Электроника'], ['2', 'Компьютеры и сети'], ['3', 'Бытовая техника'], ['4', 'Стройка и ремонт'],
['5', 'Дом и сад'], ['6', 'Авто и мото'], ['7', 'Красота и спорт'], ['8', 'Детям и мамам'], ['9', 'Работа и офис'], ['16', 'Еда']]
for i, n in enumerate(category_menu_list, start=1):
locals()["sub_cat_" + str(i)] = InlineKeyboardMarkup(row_width=1) # есть ли аналог locals()
for q, w in enumerate(all_items[n[1]]):
name_button = w
q = InlineKeyboardButton(text=name_button, callback_data=name_button)
locals()["sub_cat_" + str(i)].insert(q)
cancel_button = InlineKeyboardButton(text="Назад", callback_data="menu")
locals()["sub_cat_" + str(i)].insert(cancel_button)
@dp.callback_query_handler(text=['Эле'])
async def show_sub_cat_1(call: CallbackQuery):
await call.message.edit_reply_markup(reply_markup=sub_cat_1)
@dp.callback_query_handler(text=['Ком'])
async def show_sub_cat_2(call: CallbackQuery):
await call.message.edit_reply_markup(reply_markup=sub_cat_2)
@dp.callback_query_handler(text=['Быт'])
async def show_sub_cat_3(call: CallbackQuery):
await call.message.edit_reply_markup(reply_markup=sub_cat_3)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question