【问题标题】:Modify font size and color of a button's label in GTKAda修改 GTKAda 中按钮标签的字体大小和颜色
【发布时间】:2012-09-19 16:12:51
【问题描述】:

任何人都知道如何在 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);

但标签“Select”的特性不会改变。

有什么想法或提示吗?

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

【问题讨论】:

    标签: gtk ada gnat


    【解决方案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;
    

    我认为它对某人有用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-06-06
      • 1970-01-01
      • 1970-01-01
      • 2020-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-03
      相关资源
      最近更新 更多