I added two GtkEntry's to an app and now when I start the app one of them has focus and looks like it is ready to be edit. Dot not want any focus on any elements at the start nor for any text entry elements to have focus or being edited. I just want them to show their text, then if the user wants to change them he clicks/tabs to it, and enters the text, then hits enter and it goes back to the same state.(no highlighting, or whatever)
Asked
Active
Viewed 2,260 times
2 Answers
1
Use Gtk.Widget's grab_focus() method on any widget you like after you initialize your window

Giedrius.S
- 70
- 7
-
That was one of the first things I tried and it didn't work. I will try again... Still didn't work. The very first GtkEntry is focused. Is there a way to "tab" manually as if the keyboard tab was hit. I could do that enough times to get to something else. Unfortunately when I use the tab manually the last GtkEntry has a highlighted entry. Maybe I can make an invisible GtkEntry and use that? – Stretto Sep 11 '17 at 12:28
-
So, the hidden(well, not 100%, unfortunately) GtkEntry works but the last one always is highlighted(not focused, but as if one shift selects the text. Can get rid of it manually but ;/ It's odd that Gtk behaves this way ;/ – Stretto Sep 11 '17 at 12:55
-
Similar problem: https://stackoverflow.com/questions/20225691/how-to-remove-highlight-from-entry-in-pygtk – Stretto Sep 11 '17 at 13:01
-
Have You tried set_property('can-focus', True) on a widget you want to have initial focus, because docs say it is False by default – Giedrius.S Sep 11 '17 at 13:03
-
Yes, that does seem to help a little. What I have noticed is that the last GtkEntry seems to stay highlighed after tabing. So, when I hit tab N times and there are n < N GtkEntry's, the last one remains "highlighted(not focused). It must be a bug. Basically as it goes through each entry, it starts off editable and the text is pre-selected. Hit tab again and the selected text and focus go "off", but on the last one the text is highlighted and never goes off ;/ – Stretto Sep 11 '17 at 13:17
-
So, really what I need is for the selection of the text to be unselected when the GtkEntry is unfocused. – Stretto Sep 11 '17 at 13:19
-
Gtk Editable has method select_region() use this to accommodate your needs – Giedrius.S Sep 11 '17 at 13:38
0
I had the same problem in the first entry. My solution was to add a dummy entry as the first entry and hide it, so although it gets the focus, it is invisible:
self.v1 = Gtk.VBox()
self.dummy_field = Gtk.Entry() # workaround for focus of first entry
self.entry1 = Gtk.Entry('1')
self.entry2 = Gtk.Entry('2')
self.v1.pack_start(self.dummy_field, False, False, 0)
self.v1.pack_start(self.entry1, False, False, 0)
self.v1.pack_start(self.entry2, False, False, 0)
...
...
self.window.add(self.v1)
self.window.show_all()
self.dummy_field.hide() # dummy entry is hidden
Gtk.main()

Noa Kirsh
- 1
- 1