|
Main St, Anywhere, USA 00000 1-111-222-3333 |
|
Erlang Encryption Internet Programming News Shopping Travel Planning United States USS Wasp Netherlands Home |
with Ada.Text_IO;
with Gtk.Main;
with Gtk.Window;
with Gtk.Box;
with Gtk.GEntry; use Gtk.GEntry;
with Gtk.Button; use Gtk.Button;
with Gtk.Enums; use Gtk.Enums;
with Glib; use Glib;
with Glib.Arguments;
procedure Main is
Window : Gtk.Window.Gtk_Window;
VBox : Gtk.Box.Gtk_Box;
Entry : Gtk_Entry;
Button : Gtk_Button;
-- Callback procedure when the button is clicked
procedure On_Button_Clicked (Self : access Gtk_Button_Record'Class) is
pragma Unreferenced (Self);
Text : constant UTF8_String := Get_Text (Entry);
begin
Ada.Text_IO.Put_Line ("Entered text: " & Text);
end On_Button_Clicked;
begin
-- Initialize GtkAda
Gtk.Main.Init;
-- Create main window
Gtk.Window.Gtk_New (Window);
Window.Set_Title ("GtkAda Text & Button Example");
Window.Set_Default_Size (300, 150);
-- Create a vertical box container
Gtk.Box.Gtk_New_VBox (VBox, Homogeneous => False, Spacing => 10);
Window.Add (VBox);
-- Create the text entry widget (note: Gtk.GEntry is used due to 'entry' keyword)
Gtk_New (Entry);
Set_Text (Entry, "Hello, GtkAda!");
VBox.Pack_Start (Entry, Expand => False, Fill => False, Padding => 5);
-- Create the button
Gtk_New (Button, "Click Me");
Button.On_Clicked (On_Button_Clicked);
VBox.Pack_Start (Button, Expand => False, Fill => False, Padding => 5);
-- Connect window close event to main loop quit
Window.On_Destroy (Gtk.Main.Main_Quit);
-- Show all widgets
Window.Show_All;
-- Start the GtkAda main loop
Gtk.Main.Main;
end Main;
|