[gtkada] Dynamically Changing the Toggle Button Label

Emmanuel Briot briot at gnat.com
Thu Oct 12 10:13:11 CEST 2000


Jeff Carter writes:
 > > I want to know if there is a way to change the Label on a toggle button
 > > dynamically during program execution. I have tried everything that looks
 > > likely to me but to no avail.
 > 
 > I needed to do this, too. What I came up was:
 > 
 > 1. Create the toggle button without a label
 > 2. Create a label
 > 3. Add the label to the toggle button
 > 
 > You can then use Set_Text on the label to change the label.
 > 
 > Since buttons frequently contain labels, it would be nice to have
 > Set_Text act directly on the button to change its associated label.


This is of course doable :-)
As you can notice in the documentation, a button (and thus a toggle_button) is
a container. As documented, it can contain anything from a label (default), to
a pixmap,...
Thus, the trick here is to do the following:

   declare
      Toggle       : Gtk_Toggle_Button := <....>;
      Button_Label : Gtk_Label;
   begin
      Button_Label := Gtk_Label (Get_Child (Toggle));
      Set_Text (Button_Label, "whatever");
   end;


Note that the cast to Gtk_Label above requires that you
   with Gtk.Type_Conversion;
with GtkAda 1.2.8, although it is no longer required in the upcoming version.
Please check the documentation (user guide) for this package.

Emmanuel




More information about the gtkada mailing list