i am new to python-telegram bot, I would like to create a new inline keyboard when i press the old inline keyboard without replacing the old one.
I used "editMessageText" to handle the callback query.but it only replaces the inlinekeyboard with "reply_markup",But I want to create a new inlinekeyboard.
How to solve this problem? I searched manytimes in stack overflow.But I couldnot find the solution still now?
Please help me to solve the problem!.My image is
This is my start(CommandHandler)
def start(bot, update):
bot.sendChatAction(update.message.chat_id, action=ChatAction.TYPING)
bot.send_message(chat_id=update.message.chat_id, text=Message.CLAIM,parse_mode='html')
reply_markup = telegram.InlineKeyboardMarkup([[telegram.InlineKeyboardButton("Check New Model",callback_data="New Model")],
[telegram.InlineKeyboardButton("Reasses my Insurance",callback_data="Reasses")],
[telegram.InlineKeyboardButton("File a Claim",callback_data="claim")]])
bot.sendMessage(chat_id=update.message.chat_id, text="Choose the above one?", reply_markup=reply_markup)
This is my Callback Handler
def callback(bot,update):
query=update.callback_query
if query.data=="claim":
reply_markup = telegram.InlineKeyboardMarkup([[telegram.InlineKeyboardButton("Vehicle",callback_data="vehicle")],
[telegram.InlineKeyboardButton("Personal Accident",callback_data="accident")],
[telegram.InlineKeyboardButton("Other",callback_data="other")]])
bot.editMessageText(
message_id = update.callback_query.message.message_id,
chat_id = update.callback_query.message.chat.id,
text = "Choose the one below",
reply_markup=reply_markup
)
As per it's name, bot.edit_message_text is for editing the text of the message. You need to use bot.edit_message_reply_markup (docs).
And if you want to add some buttons to the existing keyboard (if I understood your question), just include it in the edit:
reply_markup = telegram.InlineKeyboardMarkup([
[telegram.InlineKeyboardButton("Check New Model",callback_data="New Model")],
[telegram.InlineKeyboardButton("Reasses my Insurance",callback_data="Reasses")],
[telegram.InlineKeyboardButton("File a Claim",callback_data="claim")],[telegram.InlineKeyboardButton("Vehicle",callback_data="vehicle")],[telegram.InlineKeyboardButton("Personal Accident",callback_data="accident")],
[telegram.InlineKeyboardButton("Other",callback_data="other")]
])
Related
I'm trying to build such a functionality such that whenever the user clicks in the Add button in my code, it generates a new text box, just under the old one. For example, like this:
Now, if the user were to click on add once again, a 5th text box should appear.
I've tried to achieve the same using this piece of code:
add_button = widgets.Button(description='Add',
disabled=False,
button_style='',
style={'description_width': 'initial', 'button_width': 'auto'},
icon='plus'
)
display(add_button)
add_button.on_click(add_new)
And my add_new function is simply defined as follows:
def add_new(*args):
display(widgets.Text(placeholder='Type something',description='String:'))
But this does not seem to be working nothing happens on clicking the button, any help would be appreciated. Also if there is a better way to do this, please help, I'm new to ipywidgets.
Try like this:
output = widgets.Output()
def add_new(*args):
with output:
display(widgets.Text(placeholder='Type something',description='String:'))
add_button = widgets.Button(description='Add',
disabled=False,
button_style='',
style={'description_width': 'initial', 'button_width': 'auto'},
icon='plus'
)
display(add_button)
add_button.on_click(add_new)
output
I have been tinkering with Tkinter the last couple of days to create a little game.
I have searched for how to display text ontop of an image label but there is a little downside, it won't display exactly at the spot i am looking(in this case the top left side of the label).
I tried anchor and compound together in the same label but it doesn't seem to do anything new
the text still remains in the middle.
The code looks like this:
'''Adjusting the information frame'''
self.image_info = PhotoImage(file=locate_images("_info_panel", ""))
self.label_text_info = "• Welcome to Agony,\nto play or read the rules please go to File"
self.label_info = Label(self.info, text=self.label_text_info, font=10, image=self.image_info, compound=CENTER, anchor=NW)
self.label_info.grid(row=0, column=0)
Edit:
If I try to add anything else other than compound=CENTER the text is displayed outside the boundingbox of the image on the specified side.
Moved from an edit to the question by the OP to an answer.
Use a Canvas:
'''Adjusting the information frame'''
self.image_info = PhotoImage(file=locate_images("_info_panel", ""))
self.label_text_info = "• Welcome to Agony,\nto start the game or read the rules please go to File"
self.canvas_info = Canvas(self.info, width=300, height=600)
self.canvas_info.create_image((0, 0), image=self.image_info, anchor=NW)
self.canvas_info.create_text((140, 25), text=self.label_text_info)
self.canvas_info.grid(row=0, column=0)
I was approaching it wrong from the start, I am fearly new to tkinter
and I had to use a canvas to display the items inside of.
In my "main" class I have this
tabs = Tabs(self.db)
self.setCentralWidget(tabs)
where I create a tab and show it, with Tabs inheriting QTabWidget. On the Tabs class I have this
self.livros = QWidget()
self.pessoas = QWidget()
self.addTab(self.livros, 'Livros')
self.addTab(self.pessoas, 'Pessoas')
tabela = Tabela(self.db)
where I add two tabs to my tabs. In each of them I'd like to exhibit a table. I created one table class (QTableWidget) called Tabela, where I set rows and columns and stuff, but I have no idea of how to add this table to the tabs. If I instead use it on the setCentralWidget on my main screen it works fine, but again, I'd like to exhibit in the tabs. How could I accomplish this (considering QTabWidget can't have a setCentralWidget)? Thanks very much!
I'm finding out this pattern of solving out my problem minutes after posting a question here. Anyways, the solution was pretty simple: The method setParent. On the class Tabs:
self.livros = QWidget()
self.pessoas = QWidget()
tabela = Tabela(self.db)
tabela.setParent(self.livros)
self.addTab(self.livros, 'Livros')
self.addTab(self.pessoas, 'Pessoas')
Hope this helps someone.
WinComboBox comboxBox = new WinComboBox();
comboxBox.SearchProperties[WinComboBox.PropertyNames.Name] = "Server:";
comboxBox.WindowTitles.Add("Server Settings");
comboxBox.SearchProperties[WinComboBox.PropertyNames.TechnologyName] = "Server";
comboxBox.SearchProperties[WinComboBox.PropertyNames.ControlName] = "comboBoxPlatforms";
comboxBox.SelectedItem = "Value3";
I used above code for selecting a value in a combo box using Coded UI test.
But I am getting the error
System.NotSupportedException: GetProperty of "SelectedItem" is not supported on control type: Window
Can anyone tell me what I am doing wrong or show me an alternative solution?
Sometimes i add this : comboxBox.TechnologyName = “MSAA”;
I think WindowTitles is not needed.
Try also
Mouse.click (comboBox) and playback.wait(1000); above comboxBox.SelectedItem = "Value3"; To exclude some common problems. If that solves your issue then you can start refactoring.
Ik hope it helps.
As the exception points out, the UITestControl object you have is of ControlType WINDOW, which is why you are not able to do SetProperty on it.
I will specify parent control also while searching.
WinComboBox comboxBox = new WinComboBox(WinWIndow Parent);
If your control is WinCombobox try:
combobox.SetProperty("SelectedItem", "Value3");
Also If you know the index of the item try:
combobox.SetProperty("SelectedIndex", 3);
Let me know if it resolves your issue
I'm trying to set the assigned value to a YUI Menu Button in order to use values from previous operations.
Something like remembering previous choices.
For label I already know that I can change it with:
button.set("label", "my label")
unfortunatelly I cannot change the value using: button.set("value", "my value")
Any ideia on how can I do this?
Other way would be to force a selection, but I have no ideia on how to do that.
Thanks
just found out that you can use:
var menu = button.getMenu();
var item = menu.getItem(index);
button.set("selectedMenuItem", item);
all that is left for me now is finding the needed index