Is there any global top level windows pointer in GTK ?

I know in wxWidgets, there are. And we can get them by :

import wx
wx.GetTopLevelWindows()

Is there any method in similar way with wxWidgets in GTK ?

有帮助吗?

解决方案

liberforce's advice is good: keep your lower level components modular.

However, if you really want to do it the same way as wxWidgets, use gtk_window_list_toplevels().

其他提示

The most similar will be using gtk_builder_get_object on the toplever identifier. Otherwise, just keep the pointer to the window around if you create it manually instead of using GtkBuilder. I prefer that, because this kind of "my lower level component can depend on calls to the implementation above it" often leads to ugly spaghetti code and circular dependencies in the code.

So I usually just declare a struct on the stack in the main(), so the struct will exist for the whole app life cycle, and pass a pointer to this struct in the gpointer user_data argument of callbacks. And in that structure, I may store my widgets, or other data.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top