Python 如何在电报机器人中使用“返回上一菜单”;“后退”;按钮

Python 如何在电报机器人中使用“返回上一菜单”;“后退”;按钮,python,telegram,telegram-bot,Python,Telegram,Telegram Bot,我真的在和代码作斗争。我是新的编码,我找不到任何地方的答案,这个问题。我正在用Python构建一个电报机器人,我遇到了创建“后退”按钮和“到主”按钮的问题 您可以使用内联键盘及其子键盘 你使用什么库?@EugeneLisitsky它实际上是一个考虑添加屏幕截图或错误消息来指示你所面临的问题的人。 import telebot @bot.message_handler(commands=['start']) def handle_start(message): main_greeting

我真的在和代码作斗争。我是新的编码,我找不到任何地方的答案,这个问题。我正在用Python构建一个电报机器人,我遇到了创建“后退”按钮和“到主”按钮的问题


您可以使用内联键盘及其子键盘


你使用什么库?@EugeneLisitsky它实际上是一个考虑添加屏幕截图或错误消息来指示你所面临的问题的人。
import telebot

@bot.message_handler(commands=['start'])
def handle_start(message):
   main_greeting = 'Main greeting text'
   main_menu = telebot.types.ReplyKeyboardMarkup(True, False)
   main_menu.row('Answer 1')
   main_menu.row('Answer 2', 'Answer 3')

   bot.send_message(message.from_user.id, main_greeting, reply_markup=main_menu)

def handle_text(message):
    if message.text == 'Answer 1':
        answer_1_text = 'Answer 1 text'
        answer_1_menu = telebot.types.ReplyKeyboardMarkup(True, False)
        answer_1_menu.row('Option 1')
        answer_1_menu.row('Option 2')
        answer_1_menu.row('Back') #"Back" should bring user to the main_menu

        bot.send_message(message.from_user.id, answer_1_text,
                         reply_markup=main_flavor_menu)

    elif message.text == 'Option 1'
        option_1_text = 'Select from one of the categories for further help'
        option_1_menu = telebot.types.ReplyKeyboardMarkup(True, False)
        option_1_menu.row('Category 1', 'Category 2')
        option_1_menu.row('Category 3')
        option_1_menu.row('Back', 'To Main') #"Back" should bring user to 
                                             #the answer_1_menu and "To Main" 
                                             #should bring one to main_menu

        bot.send_message(message.from_user.id, option_1_text,
                         reply_markup=option_1_menu)

    elif message.text == 'Back'
        bot.send_message(message.from_user.id, '.',
                         reply_markup=answer_1_menu-1)

    elif message.text == 'Back'
        bot.send_message(message.from_user.id, '.',
                         reply_markup=option_1_menu-1)

    elif message.text == 'To Main'
        bot.send_message(message.from_user.id, option_1_text,
                         reply_markup=main_menu)