我为telegram创建了一个bot,遇到了计算要显示内联键盘的值的数目的问题。我有一个列表和数据,可以改变,我需要在键盘上所有names
和addresses
在内联,只有我想这个键盘调整到值的数量(我知道如何创建内联按钮,显示所有的名称和地址)。但我需要每个按钮都有自己的回调)
text=[{'id': 'fd65865b-0f43-468b-80a5-04d5c9f90086', 'vendorId': '232231', 'name': 'магазин-кафетерій', 'location': {'settlement': 'Київ', 'addressLine': 'м.Київ вул.А.Ахматової 35'}, 'freeVisit': False}, {'id': '2a2d898c-853c-453b-a8c3-0acd0e1ebc8a', 'vendorId': '232830', 'name': 'магазин', 'location': {'settlement': 'Київ', 'addressLine': 'м.Київ вул.Радунська,13-А'}, 'freeVisit': False}.....]
selectKeyboard = telebot.types.InlineKeyboardMarkup( row_width=1)
lenname=[i.split("name")[0] for i in text]
print(lenname)
if 0<lenname<2:
for i in range(len(text)):
one=types.InlineKeyboardButton(text=str(text[0]['name']),callback_data="first")
selectKeyboard.add(one)
if 1<lenname<3:
for i in range(len(text)):
one=types.InlineKeyboardButton(text=str(text[0]['name'])+" ",callback_data="first")
two=types.InlineKeyboardButton(text=str(text[1]['name'])+" ",callback_data="second")
selectKeyboard.add(one,two)
if 2<lenname<4:
for i in range(len(text)):
one=types.InlineKeyboardButton(text=str(text[0]['name'])+" ",callback_data="first")
two=types.InlineKeyboardButton(text=str(text[1]['name'])+" ",callback_data="second")
three = types.InlineKeyboardButton(text=str(text[2]['name']) + " " ,callback_data="three")
selectKeyboard.add(one,two,three)
And ....
我期望动态键盘的输出,但实际输出是1个内联按钮
我知道怎么做。我总结了所有的
i
相关问题 更多 >
编程相关推荐