Search code examples
pythontelegramtelegram-botpython-telegram-bot

python telegram bot conversationbot horizontal buttons instead of vertical


In this sample, it show buttons like this:

Number1ToChoose Number2ToChoose Number3ToChoose Number4ToChoose Number5ToChoose

While I'm going to see this:

Number1ToChoose
Number2ToChoose
Number3ToChoose
Number4ToChoose
Number5ToChoose

I didn't find a way to do this up to now.


Solution

  • I'm afraid you didn't really read the documentation or the source code. The code looks like this:

    async def start(update: Update, context: ContextTypes.DEFAULT_TYPE) -> int:
        """Starts the conversation and asks the user about their gender."""
        reply_keyboard = [["Boy", "Girl", "Other"]]
    

    The reply_keyboard is defined in the documentation as a list of rows. What you have above is a list with one row with three buttons. If you change that to:

        reply_keyboard = [["Boy"],["Girl"],["Other"]]
    

    Then you'll get three rows with one button each.