tags:

views:

881

answers:

1

I have very simple window where I have 2 buttons - one for cancel, one for apply. How to set the button for apply as default one? (When I press enter, "apply" button is pressed)

However, I want to set focus to the first input widget (I can't use grab_focus() on the button)

Any suggestions?

Edit: After wuub's answer it works visually good. However, when I press the button in diffrent widget, it doesn't run callback of the default button.

Example code:

import os, sys, pygtk, gtk 

def run(button, window):
    dialog = gtk.MessageDialog(window, gtk.DIALOG_MODAL, gtk.MESSAGE_INFO, gtk.BUTTONS_OK, "OK")
    dialog.run()
    dialog.destroy()

window = gtk.Window()
window.connect("destroy", gtk.main_quit)

vbox = gtk.VBox(spacing = 10)
entry = gtk.Entry()
vbox.pack_start(entry)

button = gtk.Button(stock = gtk.STOCK_SAVE)
button.connect("clicked", run, window)
button.set_flags(gtk.CAN_DEFAULT)
window.set_default(button)
vbox.pack_start(button)

window.add(vbox)
window.show_all()
gtk.main()

EDIT2: Every input which can activate default widget must be ran

widget.set_activates_default(True)