Is there any way to the OK button, keep the focus to start the program,
and not the entry control?
Here Code:---------------------------------
#!/usr/bin/env python
import gtk
class Dialog:
def __init__(self):
dialog = gtk.Dialog("Dialog Example", None, 0,
(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_OK, gtk.RESPONSE_OK))
dialog.set_default_size(250, 300)
label = gtk.Entry()
dialog.vbox.pack_start(label, True, True, 0)
dialog.show_all()
response = dialog.run()
if response == gtk.RESPONSE_OK:
print "OK"
elif response == gtk.RESPONSE_CANCEL:
print "CANCEL"
dialog.destroy()
Dialog()
Thanks in advance!
Regards.
CRAF
_______________________________________________
pygtk mailing list py...@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/
import gtk
class Dialog:
def __init__(self):
dialog = gtk.Dialog("Dialog Example", None, 0,
(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_OK, gtk.RESPONSE_OK))
dialog.set_default_size(250, 300)
label = gtk.Entry()
buttonbox = dialog.get_action_area()
buttons = buttonbox.get_children()
dialog.set_focus(buttons[0])
dialog.vbox.pack_start(label, True, True, 0)
dialog.show_all()
response = dialog.run()
if response == gtk.RESPONSE_OK:
print "OK"
elif response == gtk.RESPONSE_CANCEL:
print "CANCEL"
dialog.destroy()
Dialog()
The above is the easiest and quickest way I can think of. Essentially, you access the ButtonBox which holds the buttons specified when constructing the Dialog and retrieve the Button. This allows you to set the focus before the Dialog is shown.
I have a feeling there is a better way, though it's not obvious to me at the moment.
Works very well!
Thank you very much.
Best Regards.
Cristian
>-----Mensaje original-----
>De: Andrew Steele <andrew...@gmx.com>
>Para: craf <pycl...@gmail.com>
>Cc: Pygtk <py...@daa.com.au>
>Asunto: Re: [pygtk] set focus in dialog
>Fecha: Fri, 18 Nov 2011 15:23:20 +0000