如何使用telethon在电报中定位和调整按钮大小
How to position and resize button in telegram using telethon
我想创建一个堆叠在一起的菜单按钮,并且足够长以容纳 telegram 聊天中的菜单选项。
按照 Telethon 指南 here, Button.inline
creates buttons close to one another in a line. I could not find any option 更改按钮位置(为菜单制作 1x10 或 2x5 等按钮网格)并且按钮不会自行调整大小以适应文本。
telethon 可以定位按钮和调整按钮大小吗?如果是这样,怎么办?
试试这个。它对我有用。
from telethon import TelegramClient, Button, events
client = TelegramClient("session", api_id, api_hash)
@client.on(events.NewMessage(pattern="/options"))
async def handler(event):
keyboard = [
[
Button.inline("First option", b"1"),
Button.inline("Second option", b"2")
],
[
Button.inline("Third option", b"3"),
Button.inline("Fourth option", b"4")
],
[
Button.inline("Fifth option", b"5")
]
]
await client.send_message(event.chat_id, "Choose an option:", buttons=keyboard)
这是结果
我想创建一个堆叠在一起的菜单按钮,并且足够长以容纳 telegram 聊天中的菜单选项。
按照 Telethon 指南 here, Button.inline
creates buttons close to one another in a line. I could not find any option 更改按钮位置(为菜单制作 1x10 或 2x5 等按钮网格)并且按钮不会自行调整大小以适应文本。
telethon 可以定位按钮和调整按钮大小吗?如果是这样,怎么办?
试试这个。它对我有用。
from telethon import TelegramClient, Button, events
client = TelegramClient("session", api_id, api_hash)
@client.on(events.NewMessage(pattern="/options"))
async def handler(event):
keyboard = [
[
Button.inline("First option", b"1"),
Button.inline("Second option", b"2")
],
[
Button.inline("Third option", b"3"),
Button.inline("Fourth option", b"4")
],
[
Button.inline("Fifth option", b"5")
]
]
await client.send_message(event.chat_id, "Choose an option:", buttons=keyboard)
这是结果