3

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?

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

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

I could not find an option:

oxidworks
  • 1,563
  • 1
  • 14
  • 37

1 Answers1

5

Just found:

5.10. How do I focus a widget? How do I focus it before its toplevel window is shown?

http://faq.pygtk.org/index.py?file=faq05.010.htp&req=show

entry2.grab_focus()

.

#!/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()
Community
  • 1
  • 1
oxidworks
  • 1,563
  • 1
  • 14
  • 37