Although both OpenGL and Direct3D are capable of producing their own application windows including menus, it is not such a straightforward task to add sub-windows to the main application, especially if these windows are to contain something other than graphical or animated content.
A graphical user interface (GUI) toolkit is a general API that allows development of applications containing user interface items such as sub-windows, menus, scrollbars and status-bars easily and efficiently. Under any *nix system there are several GUI toolkits such as the Gimp ToolKit (GTK) and Qt which also has versions for other operating systems such as Microsoft Windows and MacOS
Most of these toolkits deal with so called widgets, which is a generic term for any kind of object under the control of the toolkit.
The main flow of events when creating an application begins with initialising the toolkit, creating any widgets the application will need, connecting callbacks to any events the application needs to handle, and then passing control over to the toolkit.
Events include things like mouse button clicks, key presses and movement of the window, which are all things that the application might, and probably will need to deal with.
It is common for GUI toolkits to use the asynchronous signal/slot method of callbacks, where callback functions are connected to signals in a many to many relationship. The main advantage of such a method is that objects can co-operate with no knowledge of each other, this makes communication much simpler, and safer since there is no possible way for different objects to corrupt each others data.