Search code examples
python-3.xtelegram-botpython-telegram-bottelethon

How to customise telegram bot buttons?


I have some names in a list with unknown list length.For each name in the list should need a button customised based on the total number of buttons

name = [a,b,c,d,e,f,g,h,i,....]

main_keyboard = [[Button.inline(name[0]), Button.inline(name[1])]]

This will create buttons side side like

button1 button2

What I want output is if the length of list is 3

button1 button2
button3

if the length of list is 4

button1 button2
button3 button4

If the length of the list is 6

button1 button2 button3
button4 button5 button6

if length of the list is 8

button1 button2 button3
button4 button5 button6
button7 button8

If the length of list is greater than 12 , then the button should be in next page


Solution

  • Each Array in the main keyboard array is a separate row.

    To get the desired output, you'll need to slit your array of buttons in to chunks of your desired size:


    Set the chunk size based on the amount of buttons you wish on each line.