#!/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()
        
        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.

On Thu, 17 Nov 2011 12:42:36 -0300
craf <pyclut...@gmail.com> wrote:

> Hi.
> 
> 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   pygtk@daa.com.au
> http://www.daa.com.au/mailman/listinfo/pygtk
> Read the PyGTK FAQ: http://faq.pygtk.org/
_______________________________________________
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/

Reply via email to