When you click on the button, you need to output the remaining 5 values to the buttons from the array and
, or return
I only catch a mistake …
@ bot.message_handler (commands = ['list'])
def all_commands (message):
a = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']
key = types.InlineKeyboardMarkup ()
one = types.InlineKeyboardButton (text = a [0], callback_data = 'hex-dec')
two = types.InlineKeyboardButton (text = a [1], callback_data = 'bin-dec')
three = types.InlineKeyboardButton (text = a [2], callback_data = 'oct-dec')
four = types.InlineKeyboardButton (text = a [3], callback_data = 'str-int')
five = types.InlineKeyboardButton (text = a [4], callback_data = 'bin-hex')
nex = types.InlineKeyboardButton (text = 'Next = & gt;', callback_data = 'next')
prev = types.InlineKeyboardButton (text = '& lt; = Prev', callback_data = 'prev')
none = types.InlineKeyboardButton (text = '', callback_data = 'none')
key.row (one, two, three, four, five)
key.row (prev, none, nex)
bot.send_message (chat_id = '@ qwerzxcva', text = 'This is what I can do: \ n ...', reply_markup = key)
@ bot.callback_query_handler (func = lambda call: True)
def calling (message):
if call.data == 'next':
pass # what and how to write correctly?
if call.data == 'prev':
pass # what and how to write correctly?
bot.polling (none_stop = True)
Answer 1, authority 100%
here’s an example put together on the knee:
a = ['1', '2', '3', '4', '5', ' 6 ',' 7 ',' 8 ',' 9 ',' 10 ']
b = ['hex-dec', 'bin-dec', 'oct-dec', 'str-int', 'bin-hex', '6-hex', '7-hex', '8-hex' , '9-hex', '10 -hex ']
def keyboard (c):
if c == 1:
key = types.InlineKeyboardMarkup ()
buttons = []
for i in range (6, len (a)):
buttons.append (
types.InlineKeyboardButton (text = str (a [i]), callback_data = str (b [i])))
nex = types.InlineKeyboardButton (text = 'Next = & gt;', callback_data = 'next')
prev = types.InlineKeyboardButton (text = '& lt; = Prev', callback_data = 'prev')
key.add (* buttons)
key.add (prev, nex)
return key
else:
key = types.InlineKeyboardMarkup ()
buttons = []
for i in range (0, 5):
buttons.append (
types.InlineKeyboardButton (text = str (a [i]), callback_data = str (b [i])))
nex = types.InlineKeyboardButton (text = 'Next = & gt;', callback_data = 'next')
prev = types.InlineKeyboardButton (text = '& lt; = Prev', callback_data = 'prev')
key.add (* buttons)
key.add (prev, nex)
return key
@ bot.message_handler (commands = ['list'])
def all_commands (message):
bot.send_message (message.chat.id, 'This is what I can do: \ n ...', reply_markup = keyboard (0))
@ bot.callback_query_handler (func = lambda call: True)
def calling (call):
print (call.data)
if call.data == 'next':
bot.edit_message_text (chat_id = call.message.chat.id, message_id = call.message.message_id, text = 'Select:',
reply_markup = keyboard (1))
if call.data == 'prev':
bot.edit_message_text (chat_id = call.message.chat.id, message_id = call.message.message_id, text = 'Select:',
reply_markup = keyboard (0))
here you can replace two lists with a dictionary and pull k, v; get rid of if c == 1
, go for it!