Answer the question
In order to leave comments, you need to log in
There is a list of films, how to display a button in telegram every 10, 20, 30, etc. films, aiogram?
When you click on the "all" button, buttons come out, like 1 will be the first 10 films, 2 20 films, etc.
@dp.callback_query_handler(lambda c: c.data == 'все')
async def callback_inline(callback_query: types.CallbackQuery):
await bot.answer_callback_query(callback_query.id)
key1 = InlineKeyboardMarkup() # тут будут кнопки в зависимости от колва фильмов
for key in handlers.user_films_all():
rele1 = InlineKeyboardButton(text=f"{key}", callback_data=f"{key}")
key1.row(rele1)
await bot.edit_message_text(chat_id=callback_query.from_user.id, message_id=callback_query.message.message_id,
text=f'На цифраx будут фильмы', reply_markup=key1)
def user_films_all():
db = sql.connect('TGusers_films.db')
cur = db.cursor()
array = list(cur.execute('SELECT name_film, year_films FROM user_films'))
result = list(chunks(3, array))# для примера тут по 3
ord_dict = OrderedDict()
for i in enumerate(result, 1):
ord_dict[f'{i[0]}'] = i[1]
return ord_dict
@dp.callback_query_handler(lambda c: c.data == '1') # потом 2, 3, 4 и тд
async def process_callback_button1(callback_query: types.CallbackQuery):
number = callback_query.data
await bot.answer_callback_query(callback_query.id)
keys = InlineKeyboardMarkup(resize_keyboard=True)
for key in handlers.user_films_all().keys():
rele1 = InlineKeyboardButton(text=f"{key}", callback_data=f"{key}")
keys.row(rele1)
await bot.edit_message_text(chat_id=callback_query.from_user.id, message_id=callback_query.message.message_id,
text=f'{handlers.nubmer_exit(number)}',
reply_markup=keys)
Answer the question
In order to leave comments, you need to log in
I don't know if it's the right way to write it, but it works
amount_keys = handlers.col() # количество кнопок
@dp.callback_query_handler(lambda c: f"{amount_keys}")
async def process_callback_button1(callback_query: types.CallbackQuery):
number = callback_query.data
await bot.answer_callback_query(callback_query.id)
keys = InlineKeyboardMarkup(resize_keyboard=True)
for key in handlers.user_films_all().keys():
number_button = InlineKeyboardButton(text=f"{key}", callback_data=f"{key}")
keys.insert(number_button)
await bot.edit_message_text(chat_id=callback_query.from_user.id, message_id=callback_query.message.message_id,
text=f'{handlers.nubmer_exit(number)}',
reply_markup=keys)
def col():
s = len(user_films_all())
o = 'or'
res = ["c.data == '1'"]
for i in range(2, s+1):
if i == s:
res.append(o)
res.append(f'c.data = "{i}"')
else:
res.append(o)
res.append(f'c.data = "{i}"')
r = " ".join(res)
return r
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question