I
I
i_ikigai2020-07-30 01:35:33
Python
i_ikigai, 2020-07-30 01:35:33

How to give individual buttons in the list different properties for telegram bot buttons?

There are 3 buttons

btn_film = KeyboardButton(text='Найти фильм')
btn_D = KeyboardButton(text='Математические операции')
btn_sql = KeyboardButton(text='Запись в БД')

Here they are gathering
markup_start = ReplyKeyboardMarkup(one_time_keyboard=True,resize_keyboard=True).add(btn_film).add(btn_D).add(btn_sql)

Is it even possible to make the "btn_film" button have the property "one_time_keyboard=True" and the other buttons have it "False"?
Or can 2 packs of buttons be combined into one?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Mikhail Trainin, 2020-07-30
@Stormx480

Look. As far as I know, this is not provided for in the constructor of the ReplyKeyboardMarkup class.
But you can take it into the processing of the logic of the button itself.
When a person clicks on a button (normal), he sends a text to the bot, which you catch using a handler decorator, for example, let's take the "Find movie" button:

@bot.message_handler(regexp = 'Найти фильм')
def find_film(message):
  pass

Next, we need to add logic there to hide the keyboard after pressing the button.
There is a ReplyKeyboardRemove class for this.
Let's use them:
@bot.message_handler(regexp = 'Найти фильм')
def find_film(message):
  markup = telebot.types.ReplyKeyboardRemove()
  bot.send_message(message.chat.id, 'remove keyboard', reply_markup=markup)

Thus, the logic that you cannot put in the constructor of the ReplyKeyboardMarkup class - you can take out the handlers in the functions.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question