1

任何人都知道如何在 GTKAda 中修改按钮标签的特性。

我已经尝试过使用 Pango 的包和 Style 的包和 Widget 的包,它们不会更改属性。

代码是这样的:

Gtk_New (Button_Select, "Select");
Modify_Font (Button_Select, From_String("Helvetica 16"));
Pack_Start (Control_Box, Button_Select, False, False, 1);

但标签“选择”的特征不会改变。

任何想法或提示?

感谢您阅读并回答我的问题。

4

1 回答 1

1

我从 PHP 中的代码中找到了解决方案,我只是将命令转移到 ada,但我认为留下问题并回答它很有用。

创建按钮时,也会创建一个标签对象并将其添加到按钮中。可以得到标签对象--Get_Child--函数,然后将该标签对象作为普通标签使用。

命令如下:

Set_Markup(GTk_Label(Get_Child (Button_S)), "<span weight=""bold"" color=""blue"" size=""xx-large"">It Works!!</span>");

完整代码如下:

    with GLib;          use GLib;
    with Gtk.Window;    use Gtk.Window;
    with Gtk.Frame;     use Gtk.Frame;
    with Gtk.Button;    use Gtk.Button;
    with Gtk.Widget;    use Gtk.Widget;
    with Gtk.Label;     use Gtk.Label;
    with Pango.Font;    use Pango.Font;
    with Gtk.Handlers;
    with Gtk.Main;

    procedure button_label_test is
       Window          : Gtk_Window;
       Frame           : Gtk_Frame;
       Button_S        : Gtk_Button;

       package Handlers is new Gtk.Handlers.Callback (Gtk_Widget_Record);
       package Return_Handlers is
          new Gtk.Handlers.Return_Callback (Gtk_Widget_Record, Boolean);

       function Delete_Event (Widget : access Gtk_Widget_Record'Class)
          return Boolean is
       begin
          return False;
       end Delete_Event;

       procedure Destroy (Widget : access Gtk_Widget_Record'Class) is
       begin
          Gtk.Main.Main_Quit;
       end Destroy;

       -- This is the function to modify the characteristics of the label of the button
       procedure Clicked (Widget : access Gtk_Widget_Record'Class) is
       begin
          Set_Markup(GTk_Label(Get_Child (Button_S)), "<span weight=""bold"" color=""blue"" size=""xx-large"">It Works!!</span>");
       end Clicked;


    begin
       Gtk.Main.Init;
       Gtk.Window.Gtk_New (Window);
       Set_Default_Size (Window, 200, 200);
       Gtk.Window.Set_Title (Window, "Button Label test");
       Gtk_New (Frame);
       Gtk_New (Button_S, "Try");
       Add (Frame, Button_S);
       Add (Window, Frame);

       Return_Handlers.Connect
       (  Window,
          "delete_event",
          Return_Handlers.To_Marshaller (Delete_Event'Access)
       );
       Handlers.Connect
       (  Window,
          "destroy",
          Handlers.To_Marshaller (Destroy'Access)
       );
       Handlers.Connect
       (  Button_S,
          "clicked",
          Handlers.To_Marshaller (Clicked'Access)
       );

       Show_All (Window);
       Show (Window);

       Gtk.Main.Main;

    end button_label_test;

我认为这对某人有用。

于 2012-09-20T13:19:56.560 回答