我想出了如何将 Get_text 函数与 Entry 一起使用。
manuBriot & andlabs =
当用户按下 _Enter 时,我还在 Entry 的包中找到了用于反应的 Signal。
最后,现在一切正常。
我的程序做什么?= 它是一个窗口,看起来完全像这样: http ://pix.toile-libre.org/?img=1450777307.png
而且,在你写了一些东西并在图形条目中按 _Enter 之后,结果是在 command_line 中打印。
从 GTK 语言开始简单而有用。
WITH Gtk.Main ; USE Gtk.Main ;
WITH Gtk.Window ; USE Gtk.Window ;
WITH Gtk.Enums ; USE Gtk.Enums ;
WITH Gtk.Button ; USE Gtk.Button ;
WITH Gtk.Alignment ; USE Gtk.Alignment ;
WITH Gtk.Box ; USE Gtk.Box ;
WITH Gtk.Gentry; USE Gtk.Gentry;
WITH Ada.text_io; USE Ada.text_io;
WITH Gtk.Widget ; USE Gtk.Widget ;
with Gtk.Handlers;
PROCEDURE prototype IS
-----------------------
-- VARIABLES -- |
----------------------------------------------------------
win : Gtk_window ;
Btn1, Btn2 ,Btn3 : Gtk_Button ;
alignG, alignM ,alignD : Gtk_Alignment ;
Boite : Gtk_VBox ;
Boutons : Gtk_HBox ;
saisie : Gtk_Entry ;
----------------------------------------------------------
--Instanciation package(s) for connexion
----------------------------------------------------------
PACKAGE P_Callback IS NEW Gtk.Handlers.Callback(Gtk_Widget_Record);
USE P_Callback ;
----------------------------------------------------------
-- Handlers (or callbacks) |
----------------------------------------------------------
procedure Stop_Program(Emetteur : access Gtk_Widget_Record'class)
is
PRAGMA Unreferenced (Emetteur);
begin
Main_Quit;
end Stop_Program ;
procedure Handler_text(Ent : access Gtk_Widget_Record'class)
is begin
put_line(get_text(saisie));
end Handler_text ;
-------------------------------------------------
BEGIN
Init ;
----------------
-- NEW -- |
-------------------------------------------------
Gtk_New(win);
Gtk_New(saisie);
Gtk_New(Btn1, "Bouton 1") ;
Gtk_New(Btn2, "Bouton 2") ;
Gtk_New(Btn3, "Bouton 3") ;
Gtk_New(alignG,0.0,1.0,1.0,1.0);
Gtk_New(alignM,0.5,1.0,1.0,1.0);
Gtk_New(alignD,1.0,1.0,1.0,1.0);
Gtk_New_VBox
(Boite, homogeneous => false, Spacing => 0) ;
Gtk_New_HBox
(Boutons, homogeneous => false, Spacing => 0) ;
---------------------------------
-- Add |
---------------------------------
alignG.add(Btn1) ;
alignM.add(Btn2) ;
alignD.add(Btn3) ;
win.Add(Boite);
------------------------------------------
-- Connect |
------------------------------------------
Connect(Widget => win ,
Name => "destroy" ,
Cb => Stop_Program'access);
Connect(Widget => saisie ,
Name => "activate" ,
Cb => Handler_text'access);
------------------------------------------
-- Design Window |
------------------------------------------
Boite.Pack_Start(saisie);
Boite.Pack_Start(Boutons);
Boutons.Pack_Start(alignG);
Boutons.Pack_Start(alignM);
Boutons.Pack_Start(alignD);
win.Set_Default_Size(500,500) ;
win.set_position(Win_Pos_Mouse) ;
-- win.set_opacity(0.7) ;
win.Show_all ;
Main ;
END prototype ;