如何更改gtkada和glade中的标签

时间:2015-09-11 15:25:23

标签: ada settext glade

当我点击按钮

时,我遇到了set_text更改标签的问题

错误:

Builder results
    C:\Users\MaxPayne\Desktop\Ada workspace\Gui3\src\window_play.adb
        42:16 expected an access type with designated type "Gtk_Label_Record" defined at gtk-label.ads:189
        42:16 found package or procedure name

行中的错误:Set_Text(Label,“按钮点击:”& Natural'Image(Count));

这是示例代码:simple_glade3.adb

with Gtk;            use Gtk;
with Gtk.Main;       use Gtk.Main;
with Gtk.Widget;     use Gtk.Widget;
with Gtkada.Builder; use Gtkada.Builder;

-- the following package is user defined.
with Simple_Callbacks; use Simple_Callbacks;
with Window_Play; use Window_Play;

with Gtk.Builder; use Gtk.Builder;
with Gtk.Window; use Gtk.Window;
with Gtk.Button; use Gtk.Button;
with Gtkada.Handlers;  use Gtkada.Handlers;
use Gtkada.Handlers;

with Glib; use Glib;
with Glib.Error; use Glib.Error;
with Gtk.Main;
with Gtk.Label; use Gtk.Label;
with Gtk.Frame;     use Gtk.Frame;
with ada.Text_IO; use ada.Text_IO;


procedure Simple_Glade3 is

   Builder : Gtkada_Builder;
   error : aliased GError;
   Win   : Gtk_Window;
   ret : GUint;
   Button : Gtk_Button;

begin
   Gtk.Main.Init;

   Gtk_New (Builder);
   ret := Builder.Add_From_File ("welcomemenu.glade", error'Access);

   Register_Handler
     (Builder      => Builder,
      Handler_Name => "Main_Quit", -- from XML file <signal handler=..>
      Handler      => Simple_Callbacks.Quit'Access);

   Do_Connect (Builder);

   button := Gtk_Button (Builder.Get_Object ("btn_play"));
   button.On_Clicked (changeLabel'Access);

   Win := Gtk_Window (Builder.Get_Object ("win_main"));
   Win.Show_All;
   Gtk.Main.Main;

   Ada.Text_IO.Put_Line ("The demo is over");
   Unref (Builder);


end Simple_Glade3;

window_play.ads

with Gtkada.Builder; use Gtkada.Builder;
with Gtk.Main;
with Gtk.Button; use Gtk.Button;
package Window_Play is

   procedure Quit (Object : access Gtkada_Builder_Record'Class);
   procedure changeLabel (Self : access Gtk_Button_Record'Class);

end Window_Play;

window_play.adb

with Gtk;            use Gtk;
with Gtk.Main;       use Gtk.Main;
with Glib.Error;     use Glib.Error;
with Gtk.Widget;     use Gtk.Widget;
with Ada.Text_IO;
with Gtkada.Builder; use Gtkada.Builder;

-- the following package is user defined.
with Simple_Callbacks; use Simple_Callbacks;

with Gtk.Builder; use Gtk.Builder;
with Gtk.Window; use Gtk.Window;
with Gtk.Button; use Gtk.Button;
with Gtkada.Handlers;  use Gtkada.Handlers;

with Glib; use Glib;
with Glib.Error; use Glib.Error;
with Gtk.Main;
with Ada.Text_IO; use Ada.Text_IO;
with Gtk.Label; use Gtk.Label;


package body Window_Play is

   Builder : Gtkada_Builder;
   error : aliased GError;
   Win   : Gtk_Window;
   ret : GUint;
   Button : Gtk_Button;
   Count  : Natural := 0;

   procedure Quit (Object : access Gtkada_Builder_Record'Class) is
      pragma Unreferenced (Object);
   begin
      Gtk.Main.Main_Quit;
   end Quit;

   procedure changeLabel (Self : access Gtk_Button_Record'Class) is
   begin
     Count := Count + 1;
     Set_Text (Label, "The button clicks:" & Natural'Image (Count));
   end changeLabel;

end Window_Play;

1 个答案:

答案 0 :(得分:1)

正如Simon指出的那样,编译器在第42行没有看到名为Label的变量。相反,它会看到包Gtk.Label并猜测这是你引用的内容。 假设您的意图是更改按钮显示的内容,您应该只使用

Self.Set_Label ("The button clicks:" & Count'Img);