How to set an GTK Entry as an default active element in Python GTK2
<p>How can I set a GTK entry as default activated element / widget on start so I can insert my text without click into the entry widget first?</p>

<p>For example, when I start this script I want to insert into entry2 by default:</p>

<pre><code>#!/usr/bin/python
# -*- coding: utf-8 -*-

import gtk

window = gtk.Window(gtk.WINDOW_TOPLEVEL)
mainbox    = gtk.VBox()
window.add(mainbox)
mainbox.pack_start(gtk.Label("Label 1"))
entry1 = gtk.Entry()
mainbox.pack_start(entry1)
mainbox.pack_start(gtk.Label("Label 2"))
entry2 = gtk.Entry()
mainbox.pack_start(entry2)
window.show_all()
gtk.main()
</code></pre>

<p>I could not find an option:</p>

<ul>
<li><a href="http://www.pygtk.org/pygtk2reference/class-gtkentry.html" rel="nofollow">http://www.pygtk.org/pygtk2reference/class-gtkentry.html</a></li>
<li><a href="http://www.pygtk.org/pygtk2reference/class-gtkwidget.html" rel="nofollow">http://www.pygtk.org/pygtk2reference/class-gtkwidget.html</a></li>
</ul>

<p>Just found:</p>

<p><strong>5.10. How do I focus a widget? How do I focus it before its toplevel window is shown?</strong></p>

<p><a href="http://faq.pygtk.org/index.py?file=faq05.010.htp&amp;req=show" rel="nofollow">http://faq.pygtk.org/index.py?file=faq05.010.htp&amp;req=show</a></p>

<pre><code>entry2.grab_focus()
</code></pre>

<p>.</p>

<pre><code>#!/usr/bin/python
# -*- coding: utf-8 -*-

import gtk

window = gtk.Window(gtk.WINDOW_TOPLEVEL)
mainbox    = gtk.VBox()
window.add(mainbox)
mainbox.pack_start(gtk.Label("Label 1"))
entry1 = gtk.Entry()
mainbox.pack_start(entry1)
mainbox.pack_start(gtk.Label("Label 2"))
entry2 = gtk.Entry()
mainbox.pack_start(entry2)

entry2.grab_focus()

window.show_all()

gtk.main()
</code></pre>

python gtk2