@alex_under77

Можно ли сделать кнопку inline, в telegram боте в две строки?

Чтобы пользователь выбрал один из вариантов, от бота нужно слать сообщения с inline кнопками. Можно ли текст переносить на другую строку? Если да, то как?
  • Вопрос задан
  • 610 просмотров
Пригласить эксперта
Ответы на вопрос 1
@RiderMC
Конечно можно.
Вот пример:
import telebot
from config import TOKEN

bot = telebot.TeleBot(TOKEN)

@bot.message_handler(commands=['start'])
def process_start(message):
    keyboard = telebot.types.ReplyKeyboardMarkup(True)
    keyboard.row('Выбери меня')
    msg = bot.send_message(message.chat.id, text = 'Нажми кнопку в меню', reply_markup = keyboard )


@bot.message_handler(content_types = ['text'])
def step1(message):
    menu1 = telebot.types.InlineKeyboardMarkup()
    menu1.add(telebot.types.InlineKeyboardButton(text = 'Первая кнопка', callback_data ='first'))
    menu1.add(telebot.types.InlineKeyboardButton(text = 'Вторая кнопка', callback_data ='second'))

    if message.text == 'Выбери меня':
        msg = bot.send_message(message.chat.id, text ='Нажми первую inline кнопку', reply_markup = menu1)
        bot.register_next_step_handler(msg, step2)


@bot.callback_query_handler(func=lambda call: True)
def step2(call):
    menu2 = telebot.types.InlineKeyboardMarkup()
    menu2.add(telebot.types.InlineKeyboardButton(text = 'Третья кнопка', callback_data ='third'))
    menu2.add(telebot.types.InlineKeyboardButton(text = 'Четвертая кнопка', callback_data ='fourth'))

    if call.data == 'first':
        msg = bot.send_message(call.message.chat.id, 'Нажми третью кнопку', reply_markup = menu2)
        bot.register_next_step_handler(msg, step3)

def step3(call):
    if call.data == 'third':
        msg = bot.send_message(call.message.chat.id, 'Конец')
    else:
        pass
  

bot.polling(none_stop=True)

5ec3ca5529bde760985712.png

Взял отсюда: https://qna.habr.com/q/774821
Ответ написан
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы