I have this code which has 1 label and 3 buttons. What I want is to change the text of the label if I press a certain button. If I click the first button the label text will change to "Hello" and if I click the second button the label text will change to "World" and lastly if I click the third button the label text should become "Hello World".
with Gdk.Event; use Gdk.Event;
with Gtk.Box; use Gtk.Box;
with Gtk.Label; use Gtk.Label;
with Gtk.Widget; use Gtk.Widget;
with Gtk.Main;
with Gtk.Window; use Gtk.Window;
with Gtk.Button; use Gtk.Button;
with Gtk.Grid; use Gtk.Grid;
procedure Main is
Win : Gtk_Window;
Label : Gtk_Label;
Box : Gtk_Vbox;
Button: Gtk_Button;
Button2: Gtk_Button;
Button3: Gtk_Button;
Grid : Gtk_Grid;
function Delete_Event_Cb
(Self : access Gtk_Widget_Record'Class;
Event : Gdk.Event.Gdk_Event)
return Boolean;
---------------------
-- Delete_Event_Cb --
---------------------
function Delete_Event_Cb
(Self : access Gtk_Widget_Record'Class;
Event : Gdk.Event.Gdk_Event)
return Boolean
is
pragma Unreferenced (Self, Event);
begin
Gtk.Main.Main_Quit;
return True;
end Delete_Event_Cb;
begin
-- Initialize GtkAda.
Gtk.Main.Init;
-- Create a window with a size of 100x120
Gtk_New (Win);
Win.Set_Default_Size (100, 120);
-- Create a box to organize vertically the contents of the window
Gtk_New_Vbox (Box);
Win.Add (Box);
-- Add a label
Gtk_New (Label, "Hello world.");
Box.Add (Label);
-- Add a Grid
Gtk_New (Grid);
Box.Add (Grid);
-- Add the first button to the grid
Gtk_New (Button, "Hello");
Grid.Attach (Button, 0, 0, 1, 1);
-- Add Second button to the grid
Gtk_New (Button2, "World");
Grid.Attach (Button2, 1, 0, 1, 1);
-- Add the third button to the grid
Gtk_New (Button3, "Hello World!");
Grid.Attach (Button3, 0, 1, 2, 1);
-- Stop the Gtk process when closing the window
Win.On_Delete_Event (Delete_Event_Cb'Unrestricted_Access);
-- Show the window and present it
Win.Show_All;
Win.Present;
-- Start the Gtk+ main loop
Gtk.Main.Main;
end Main;
What should I add to make that happen?