Answer the question
In order to leave comments, you need to log in
Error if call.data == "1": NameError: name 'call' is not defined why does it occur?
Here is the code:
@bot.message_handler(commands=['Test'])
def ms(message):
MNU = 0
markup = types.InlineKeyboardMarkup()
Num1 = types.InlineKeyboardButton(text='1', callback_data ='1')
Num2 = types.InlineKeyboardButton(text='2', callback_data ='2')
Num3 = types.InlineKeyboardButton(text='3', callback_data ='3')
Num4 = types.InlineKeyboardButton(text='4', callback_data ='4')
Num5 = types.InlineKeyboardButton(text='5', callback_data ='5')
Num6 = types.InlineKeyboardButton(text='6', callback_data ='6')
Num7 = types.InlineKeyboardButton(text='7', callback_data ='7')
Num8 = types.InlineKeyboardButton(text='8', callback_data ='8')
Num9 = types.InlineKeyboardButton(text='9', callback_data ='9')
Num9 = types.InlineKeyboardButton(text='+', callback_data ='D')
Num9 = types.InlineKeyboardButton(text='-', callback_data ='V')
markup.add(Num1, Num2, Num3, Num4, Num5, Num6, Num7, Num8, Num9)
bot.send_message(message.chat.id, "Ето калькулятор! Можно виполнить какието математические операции", reply_markup = markup)
if call.data == "1":
MNU = 1
elif call.data == "2":
MNU = 2
elif call.data == "3":
MNU = 3
elif call.data == "4":
MNU = 4
elif call.data == "5":
MNU = 5
elif call.data == "6":
MNU = 6
elif call.data == "7":
MNU = 7
elif call.data == "8":
MNU = 8
elif call.data == "9":
MNU = 9
if MNU >= 1:
markup = types.InlineKeyboardMarkup()
Num2_1 = types.InlineKeyboardButton(text='1', callback_data ='2_1')
Num2_2 = types.InlineKeyboardButton(text='2', callback_data ='2_2')
Num2_3 = types.InlineKeyboardButton(text='3', callback_data ='2_3')
Num2_4 = types.InlineKeyboardButton(text='4', callback_data ='2_4')
Num2_5 = types.InlineKeyboardButton(text='5', callback_data ='2_5')
Num2_6 = types.InlineKeyboardButton(text='6', callback_data ='2_6')
Num2_7 = types.InlineKeyboardButton(text='7', callback_data ='2_7')
Num2_8 = types.InlineKeyboardButton(text='8', callback_data ='2_8')
Num2_9 = types.InlineKeyboardButton(text='9', callback_data ='2_9')
markup.add(Num2_1, Num2_2, Num2_3, Num2_4, Num2_5, Num2_6, Num2_7, Num2_8, Num2_9)
bot.send_message(message.chat.id, "Внимание калькулятор Version - 1.0 поддерживает только додавание и отнимание", reply_markup = markup)
if call.data == "2_1":
res = MNU + 1
bot.answer_callback_query(call.id, text=res)
elif call.data == "2_2":
res = MNU + 2
bot.answer_callback_query(call.id, text=res)
elif call.data == "2_3":
res = MNU + 3
bot.answer_callback_query(call.id, text=res)
elif call.data == "2_4":
res = MNU + 4
bot.answer_callback_query(call.id, text=res)
elif call.data == "2_5":
res = MNU + 5
bot.answer_callback_query(call.id, text=res)
elif call.data == "2_6":
res = MNU + 6
bot.answer_callback_query(call.id, text=res)
elif call.data == "2_7":
res = MNU + 7
bot.answer_callback_query(call.id, text=res)
elif call.data == "2_8":
res = MNU + 8
bot.answer_callback_query(call.id, text=res)
elif call.data == "2_9":
res = MNU + 9
bot.answer_callback_query(call.id, text=res)
Answer the question
In order to leave comments, you need to log in
Before creating anything, it is better to read some books / watch videos. And also familiarize yourself with the library with which you work. If you ask a question for every mistake, things will not go further, learn the basics.
https://github.com/eternnoir/pyTelegramBotAPI/blob...
@bot.message_handler(commands=['Test'])
def ms(message):
MNU = 0
markup = types.InlineKeyboardMarkup()
Num1 = types.InlineKeyboardButton(text='1', callback_data ='1')
Num2 = types.InlineKeyboardButton(text='2', callback_data ='2')
Num3 = types.InlineKeyboardButton(text='3', callback_data ='3')
Num4 = types.InlineKeyboardButton(text='4', callback_data ='4')
Num5 = types.InlineKeyboardButton(text='5', callback_data ='5')
Num6 = types.InlineKeyboardButton(text='6', callback_data ='6')
Num7 = types.InlineKeyboardButton(text='7', callback_data ='7')
Num8 = types.InlineKeyboardButton(text='8', callback_data ='8')
Num9 = types.InlineKeyboardButton(text='9', callback_data ='9')
Num9 = types.InlineKeyboardButton(text='+', callback_data ='D')
Num9 = types.InlineKeyboardButton(text='-', callback_data ='V')
markup.add(Num1, Num2, Num3, Num4, Num5, Num6, Num7, Num8, Num9)
bot.send_message(message.chat.id, "Ето калькулятор! Можно виполнить какието математические операции", reply_markup = markup)
@bot.callback_query_handler(func=lambda call: True)
def answer(call):
if call.data == "1":
MNU = 1
elif call.data == "2":
MNU = 2
elif call.data == "3":
MNU = 3
elif call.data == "4":
MNU = 4
elif call.data == "5":
MNU = 5
elif call.data == "6":
MNU = 6
elif call.data == "7":
MNU = 7
elif call.data == "8":
MNU = 8
elif call.data == "9":
MNU = 9
if MNU >= 1:
markup = types.InlineKeyboardMarkup()
Num2_1 = types.InlineKeyboardButton(text='1', callback_data ='2_1')
Num2_2 = types.InlineKeyboardButton(text='2', callback_data ='2_2')
Num2_3 = types.InlineKeyboardButton(text='3', callback_data ='2_3')
Num2_4 = types.InlineKeyboardButton(text='4', callback_data ='2_4')
Num2_5 = types.InlineKeyboardButton(text='5', callback_data ='2_5')
Num2_6 = types.InlineKeyboardButton(text='6', callback_data ='2_6')
Num2_7 = types.InlineKeyboardButton(text='7', callback_data ='2_7')
Num2_8 = types.InlineKeyboardButton(text='8', callback_data ='2_8')
Num2_9 = types.InlineKeyboardButton(text='9', callback_data ='2_9')
markup.add(Num2_1, Num2_2, Num2_3, Num2_4, Num2_5, Num2_6, Num2_7, Num2_8, Num2_9)
bot.send_message(call.message.chat.id, "Внимание калькулятор Version - 1.0 поддерживает только додавание и отнимание", reply_markup = markup)
if call.data == "2_1":
res = MNU + 1
bot.answer_callback_query(call.id, text=res)
elif call.data == "2_2":
res = MNU + 2
bot.answer_callback_query(call.id, text=res)
elif call.data == "2_3":
res = MNU + 3
bot.answer_callback_query(call.id, text=res)
elif call.data == "2_4":
res = MNU + 4
bot.answer_callback_query(call.id, text=res)
elif call.data == "2_5":
res = MNU + 5
bot.answer_callback_query(call.id, text=res)
elif call.data == "2_6":
res = MNU + 6
bot.answer_callback_query(call.id, text=res)
elif call.data == "2_7":
res = MNU + 7
bot.answer_callback_query(call.id, text=res)
elif call.data == "2_8":
res = MNU + 8
bot.answer_callback_query(call.id, text=res)
elif call.data == "2_9":
res = MNU + 9
bot.answer_callback_query(call.id, text=res)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question