my button text is too long to fit in one line of my inline keyboard for the python telegram bot. "\n" wont do.
Code info: /key is the only command it understands. It reads the API token from the file token.txt in the code directory.
Here is my code:
from pprint import pprint
from telegram.ext import Updater
from telegram.ext import CommandHandler
from telegram.ext import MessageHandler, Filters
from telegram.ext import InlineQueryHandler
from telegram.ext import CallbackQueryHandler
from telegram import InlineKeyboardButton, InlineKeyboardMarkup
from telegram import InlineQueryResultArticle, InputTextMessageContent
import logging
import time, threading, pickle
file = open("token.txt", "r")
TOKEN = file.read()
updater = Updater(TOKEN)
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',level=logging.INFO)
dispatcher = updater.dispatcher
def start(bot, update):
bot.send_message(chat_id=update.message.chat_id, text="I'm a bot, please talk to me!")
start_handler = CommandHandler('start', start)
dispatcher.add_handler(start_handler)
def key_menu(bot, update):
text = "Some really long text I\n want on two rows :D"
callback = "nothing"
keyboard = []
keyboard.append([InlineKeyboardButton(text, callback_data = callback)])
reply_markup = InlineKeyboardMarkup(keyboard)
update.message.reply_text('Some text', reply_markup=reply_markup)
key_menu_handler = CommandHandler('key', key_menu, pass_args=False)
dispatcher.add_handler(key_menu_handler)
updater.start_polling()
The second message is with the "\n" inserted. The first one is just text. Another option would be for everyone to get a bigger phone :D
Not possible for InlineKeyboardButton
, but possible for ReplyKeyboardMarkup
(it is bigger and support resize option) if it works for you.
But preferred way is to show that really long text in message and for button - use really short version for inline buttons.
Example:
buttons = [
['Some really long text I \n'
'want on two rows :D'],
['Some really long text I \n'
'want on two rows :D']
]
keyboard = ReplyKeyboardMarkup(buttons, resize_keyboard=True)
update.message.reply_text('Some message', reply_markup=keyboard)
Result:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With