GTK+ is an event-driven toolkit; that means that nothing happens unless an event is emitted and a callback is registered to receive it. The events in GTK+ are implemented through signals, and registering a callback for a signal is called connecting. Signals include most events involved in the GUI behavior and communication, including button click events or the window life cycle.
Did you notice that, in our hello world example, the Quit
button would exit the application, but that closing the window did not? That's because we didn't connect any callback to the window destroy signal. We can fix this by adding the following lines to handle this case:
window.Connect("destroy", func() { gtk.MainQuit() })
This code connects the provided anonymous function to the destroy
signal ofwindow
. When the signal is emitted, the function is called and the application will now exit correctly. As the gtk.MainQuit()
function takes 0 parameters, we could write the same more concisely...