Run code when gtk.widget becomes visible

Is there a function that gets called on a gtk.widget every time the widget gets drawn to the surface, like react’s ‘render’?

I want to be able to perform an action whenever the widget becomes visible.

This is a python app.

If you want to know when a widget will be drawn, you can use the “mapped” state and the map signal; a mapped widget means:

  • the widget is marked as visible
  • every parent until the top level is also marked as visible

GTK does not track visibility, so this will not help you if the widget is visible but offscreen and gets moved on screen. Widgets are also visible by default, so this is less useful than you’d probably want.

So, the real question is: what are you trying to achieve? What kind of “visibility” are you looking for, and what kind of action do you want to perform?

Thank you, the map signal worked great.

I had a ListBox and I wanted to be able to be able to call grab_focus() on one of the ListRows when the parent of the ListBox came into view- such as when the tab that contained the ListBox was clicked.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.