Files
ronis_0505 5662d8877a
Some checks failed
continuous-integration/drone Build is failing
MVP
2025-07-27 22:17:28 +03:00

36 lines
1.6 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

from aiogram.types import InlineKeyboardButton, InlineKeyboardMarkup, KeyboardButton
from aiogram.utils.keyboard import InlineKeyboardBuilder, ReplyKeyboardBuilder
def button_create(iterable: iter, width: int = 1):
""" Функуия для преобразования списка в кнопки для клавиатуры """
kb_builder = ReplyKeyboardBuilder()
kb_builder.row(*[KeyboardButton(text=f'{iterable[i]}') for i in range(len(iterable))], width=width)
return kb_builder.as_markup(resize_keyboard=True, one_time_keyboard=True)
def create_inline_kb(width: int = 1,
*args: str, **kwargs: str) -> InlineKeyboardMarkup:
# Инициализируем билдер
kb_builder = InlineKeyboardBuilder()
# Инициализируем список для кнопок
buttons: list[InlineKeyboardButton] = []
# Заполняем список кнопками из аргументов args и kwargs
if args:
for button in args:
buttons.append(InlineKeyboardButton(
text=button,
callback_data=button))
if kwargs:
for button, text in kwargs.items():
buttons.append(InlineKeyboardButton(
text=text,
callback_data=button))
# Распаковываем список с кнопками в билдер методом row c параметром width
kb_builder.row(*buttons, width=width)
# Возвращаем объект инлайн-клавиатуры
return kb_builder.as_markup(resize_keyboard=True, one_time_keyboard=True)