Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Programming
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Databases
Mail Systems
openSolaris
Eclipse Documentation
Techotopia.com
Virtuatopia.com
Answertopia.com

How To Guides
Virtualization
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Windows
Problem Solutions
Privacy Policy

  




 

 

Gtk+/Gnome Application Development
Prev Home Next

Entering the Main Loop

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.

Gtk+/Gnome Application Development
Prev Home Next

 
 
  Published under free license. Design by Interspire