0

I want a key press to be mapped with a button click function in Gtk-python, i.e. if Enter key is pressed, the data-process function should execute, which is called by pressing the process button.

Can this be done?

4
  • You have not given sufficient information to solve the problem. For example, which widget has the focus while Enter is being pressed? Commented May 11, 2013 at 10:48
  • The thing is , when you commented, you have 2 choices: either press the enter key, or click the Add comment button. so, both actions call the same function.I want to do a similar thing in my app Commented May 11, 2013 at 12:22
  • In that analogy, the choice of pressing "enter" is available only while the comment text area is focused. The question is, which widget is focused in your application? A GtkEntry, a GtkTextView, or something else? Commented May 11, 2013 at 14:40
  • Why don't you consider adding key-press-event or key-release-event and check the event passed to the callback for Enter key and call your button click function? As mentioned by user4815162342 key events are sent to the current focus widget. Commented May 11, 2013 at 18:36

2 Answers 2

1

Speculating this might a Gtk.Dialog, you can set the default response.

gtk_dialog_set_default_response ():

Sets the last widget in the dialog's action area with the given response_id as the default widget for the dialog. Pressing "Enter" normally activates the default widget.

Sign up to request clarification or add additional context in comments.

Comments

0

Assuming you are using a gtk.Entry() and a gtk.Button(), I think what you need to do is just connecting the gtk.Entry() to your data-process function like this: b = gtk.Button("Process") b.connect("clicked", data-process) e = gtk.Entry() e.connect("activate", data-process)

That should do the "Trick".

Hope this helped.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.