4 window = Gtk::Window.new
6 # The program will directly end upon 'delete_event'.
7 window.signal_connect('delete_event') do
12 # We create a box to pack widgets into.
13 # This is described in detail in the following section.
14 # The box is not really visible, it is just used as a tool to arrange
16 box1 = Gtk::HBox.new(true, 0)
18 # Put the box into the main window.
21 # Creates a new button with the label "Button 1".
22 button3 = Gtk::Button.new("Shut down")
23 button1 = Gtk::Button.new("Restart")
24 button2 = Gtk::Button.new("Suspend")
25 button4 = Gtk::Button.new("Lock screen")
27 # Now when the button is clicked, we call the "callback" method
28 # with a reference to "button 1" as its argument.
29 button2.signal_connect( "clicked" ) do
33 button3.signal_connect("clicked") do
38 button1.signal_connect("clicked") do
39 `sudo shutdown -h now`
42 button4.signal_connect("clicked") do
45 # Instead of window.add, we pack this button into the invisible
46 # box, which has been packed into the window.
47 box1.pack_start(button3, true, true, 0)
48 box1.pack_start(button1, true, true, 0)
49 box1.pack_start(button2, true, true, 0)
50 box1.pack_start(button4, true, true, 0)