Home > front end >  How do I prevent looping, unless I press the button, and it shows the next one and so on?
How do I prevent looping, unless I press the button, and it shows the next one and so on?

Time:12-06

how do I show only one message in a loop until I press the button or type, and then it shows the next message?

picture of it now, its shows all the messages, and I want to create button which only then pressed it shows the next one

for job in jobs:
        def gen_markup():
            markup = InlineKeyboardMarkup()
            markup.row_width = 1
            markup.add(InlineKeyboardButton(text='לאתר מתגייסים', url=job[3]))
            return markup
        if int(job[6]) <= int(user.dpr) and int(job[7]) <= int(user.profil) and job[4] == user.sex or job[5] == user.sex:
            bot.send_message(message.chat.id, "<b>"   str(job[1])   "</b>"   "\n"   str(job[2]), reply_markup = gen_markup(), parse_mode='HTML')

CodePudding user response:

Do you mean, you want to send a message with a button, and if that button is clicked, you'll proceed to send the next message?

CodePudding user response:

you can use something like this, after the button is clicked it will call the other data with new markup and send message

@bot.callback_query_handler(func=lambda call: True)
def callback_query(call):
    
    def gen_markup():
            markup = InlineKeyboardMarkup()
            markup.row_width = 1
            markup.add(InlineKeyboardButton(text='לאתר מתגייסים', url=job[3]))
            return markup
        
    def gen_marku1p():
            markup = InlineKeyboardMarkup()
            markup.row_width = 1
            markup.add(InlineKeyboardButton(text='לאתר מתגייסים', url=job[3]))
            return markup
        
    def gen_markup2():
            markup = InlineKeyboardMarkup()
            markup.row_width = 1
            markup.add(InlineKeyboardButton(text='לאתר מתגייסים', url=job[3]))
            return markup
        
    if call.data == "markup button text":
        bot.send_message(call.chat.id, 'text', parse_mode="html", reply_markup = gen_markup())
        
    elif call.data == "another markup button text":
        bot.send_message(call.chat.id, 'text', parse_mode="html", reply_markup = gen_markup1())
        
    elif call.data == "another markup button text":
        bot.send_message(call.chat.id, 'text', parse_mode="html", reply_markup = gen_markup2())
  • Related