Once everything is set up, two steps remain: you need
to show the window on the screen, and wait for user
input.
gtk_widget_show_all(window);
gtk_main();
return 0;
|
gtk_widget_show_all()
recursively calls
gtk_widget_show() on a container and its
children. The following code would have the same
effect in this case:
gtk_widget_show(label);
gtk_widget_show(button);
gtk_widget_show(window);
|
It's necessary to show each and every widget that you
want to appear on the screen. The opposite operation
is called
gtk_widget_hide(); widgets start their life
hidden, and can be re-hidden/re-shown any number of
times. It's good practice to show all child widgets
before showing the outermost container; otherwise,
the user will see the container appear first,
followed by its children. Widgets are not actually
visible on the screen until their parent container is
shown---the exception to the rule is GtkWindow, since it has no parent.
Once your widgets have been shown, you want to wait
for the user to do something with them. gtk_main() enters the GTK+ main loop;
the main loop is event-driven. That is, user actions
trigger events which
generally result in signals being emitted and your
callbacks being called.
gtk_main() blocks indefinitely, waiting for and
responding to user input. The main loop is described
in more detail in the
section called The Main Loop. Events and
their relation to the main loop are described in the section called
Events in the chapter called GDK
Basics.