我从 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;
我认为这对某人有用。