我创建了两个按钮,一个显示 Gtk_Radio_Button 和一个显示 GtK_label 的按钮,但是当我单击按钮时没有任何反应。我不明白为什么它不起作用但代码编译并运行而没有发现任何错误。
main_Program.adb
With Gtk.Window; Use Gtk.Window;
With Gtk.Button; Use Gtk.Button;
With Gtk.Grid; Use Gtk.Grid;
With file; Use file;
Procedure main_program is
Bouton : Gtk_Button;
Bouton2 : Gtk_Button;
Win : Gtk_Window;
Test : Test_Record;
begin
Gtk.Main.Init;
Init_Grid (Container => Test);
Gtk_New (Win);
Win.Add (Test.Grid);
Win.Set_Default_Size (Width => 600,
Height => 400);
Gtk_New (Bouton,Label => "Bouton");
Test.Grid.Attach (Bouton,0,0);
P.Connect (Widget => Bouton,
Name => Signal_Clicked,
Marsh => Test2.P.To_Marshaller (Init_Button'Access),
After => False);
Gtk_New (Bouton2,Label => "Bouton2");
Test.Grid.Attach (Bouton2,50,4);
P.Connect (Widget => Bouton2,
Name => Signal_Clicked,
Marsh => Test2.P.To_Marshaller (Init_Text'Access),
After => False);
Win.Show_All;
Main;
end Main_Program;
文件.ads
With Gtk.Label; Use Gtk.Label;
With Gtk.Radio_Button; Use Gtk.Radio_Button;
With Gtk.Grid; Use Gtk.Grid;
With Gtk.Handlers;
Package file is
type Test_Record is record
Text : Gtk_Label;
Grid : Gtk_Grid;
Button_Radio : Gtk_Radio_Button;
end record;
Procedure Init_Text ( Self : access Gtk_Widget_Record'Class );
-- Callback for create the text
Procedure Init_Button (Self : access Gtk_Widget_Record'Class );
-- Callback for Initialize the Radio Button;
Procedure Init_Grid (Container : out Test_Record);
-- Initialize the Gtk.Grid.Gtk_Grid
Package P is new Gtk.Handlers.Callback (Gtk_Widget_Record);
Use P;
end file;
文件.adb
With file; Use file;
Package body file is
Procedure Init_Grid ( Container : out Test_Record ) is
begin
Gtk_New (Container.Grid);
end Init_Grid;
Procedure Init_Button ( Self : access Gtk_Widget_Record'Class ) is
V : Test_Record;
begin
Init_Grid (Container => V);
Gtk_New (V.Button_Radio,
Group => null,
Label => "Button Radio");
V.Grid.Attach (V.Button_Radio,0,50);
V.Grid.Show;
end Init_Button;
Procedure Init_Text (Self : access Gtk_Widget_Record'Class) is
V : Test_Record;
begin
Init_Grid (Container => V);
Gtk_New (V.Text);
V.Text.Set_Label ("Hello,World");
V.Grid.Attach (V.Text,150,0);
V.Grid.Show;
end Init_Text;
end file;
我希望当我单击第一个按钮时,它会显示一个单选按钮,而当我单击第二个按钮时,它会显示一个标签。