-2

I have a Python code where on start I can print one inline button per row. I want to modify to print 2 inline buttons in a row. How can I modify the code?

@app.on_message(filters.command("start"))
async def mute_user(_, message):
    group_id = message.chat.id
    kn = []

    for khp in Config.groups_button:
        print(khp)
        x = khp.split("#")[0]
        p = khp.split("#")[1]
        lpo = [InlineKeyboardButton(x, url=p)]
        kn.append(lpo)

    print(kn)

    reply_markup = InlineKeyboardMarkup(
        kn
    )
Chris
  • 26,361
  • 5
  • 21
  • 42
Rinku
  • 81
  • 2
  • 14
  • What framework or package are you using? Please review how to create a [mre]. – CrazyChucky Sep 02 '22 at 18:02
  • Ah Sorry! It's using Pyrogram. – Rinku Sep 03 '22 at 20:11
  • 1
    Pro tip: if you can, phrase your requests as "how can I fix/write/modify ..." rather than asking people to do it for you. Readers will be much more likely to assist if they can see you understand the project is still yours to do. – halfer Sep 03 '22 at 20:22
  • 1
    Could you also indicate what the program does presently, and what specific trouble you are having in adding a button? Where would the button be rendered? Is this for a Telegram plugin? – halfer Sep 03 '22 at 20:23

1 Answers1

0

Pyrogram's InlineKeyboard needs a List of Lists. The outer list is the rows, whereas the inner list is the buttons on each row. If you want two buttons on one row, make a list with two items.

keyboard = InlineKeyboardMarkup(
    [
        [ # Row 1
            InlineKeyboardButton(..), # Two buttons next to each other
            InlineKeyboardButton(..)
        ],
        [ # Row 2
            InlineKeyboardButton(..) # A single button
        ]
    ]
)
# You can then easily attach above keyboard:
app.send_message(.., reply_markup=keyboard)

InlineKeyboardMarkup
List of button rows, each represented by a List of InlineKeyboardButton objects. https://docs.pyrogram.org/api/types/InlineKeyboardMarkup

ColinShark
  • 1,047
  • 2
  • 10
  • 18