A
A
alwaystried2022-04-03 18:54:53
Python
alwaystried, 2022-04-03 18:54:53

How to pass button values ​​to a variable?

how to pass the value of a variable from the button? I tried to implement something similar, but unfortunately I couldn't. Are there any other solutions to this problem?

The code:

variable = 0 #где то далеко

@dp.callback_query_handler(text="Купить билет")
async def buyit(query: CallbackQuery):
    keycheck = InlineKeyboardMarkup(row_width=2).add(
        InlineKeyboardButton(text="Политика Конфиденциальности", url="http://2.pdf"),
        InlineKeyboardButton(text="Публичная оферта", url="http://1.pdf"),
        InlineKeyboardButton(text="Согласен", callback_data="check:1"),
        InlineKeyboardButton(text="Не согласен", callback_data="check:2"),
    )
    await query.message.edit_text("Прежде чем купить билет, пожалуйста, прочтите политику конфиденциальности и публичную оферту", reply_markup=keycheck)
    global variable
    variable = int(query.data.split(":")[1])
    if variable == 1:
        print(1)
    elif variable ==2:
        print(2)

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question