2012-09-19 186 views
1

任何人都知道如何修改GTKAda中按钮标签的特性。修改GTKAda中按钮标签的字体大小和颜色

我已经试过用Pango的包和Widget的包的Style包,他们不改变属性。

的代码是这样的:

Gtk_New (Button_Select, "Select"); 
Modify_Font (Button_Select, From_String("Helvetica 16")); 
Pack_Start (Control_Box, Button_Select, False, False, 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; 

我认为这将是对别人有用。

相关问题