Date: Thu, 9 Oct 2003 14:36:28 +0200 To: Remi Vanicat Cc: lablgtk at kaba.or.jp Subject: Re: changing the text of a button ? Message-ID: <20031009123628.GA20205 at iliana> References: <87n0caipea.dlv at wanadoo.fr> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline In-Reply-To: <87n0caipea.dlv at wanadoo.fr> From: Sven Luther On Thu, Oct 09, 2003 at 02:09:17PM +0200, Remi Vanicat wrote: > Sven Luther writes: > > > Hello, > > > > I would like to change the text of a button, but have difficulties doing > > this. > > > > It seems to me that the button is a container, which contains a label as > > only child, and thus i tried to do this : > > > > let text = ((List.hd suite#children) :> GMisc.label) in > > text#set_text "Foo" > > Ttt, a container contain widget, and if you can transform a label into > a widget with coercion, you can do the converse (by the way, I really > have to learn which one is upcast, and which one is downcast). > > One way of doing it is : > > let label_aswidget = (List.hd suite#children)#as_widget in > let gtklabel = GtkMisc.Label.cast label_aswidget in > let text = new GMisc.label gtklabel in > text#set_text "Foo" Ok, thanks. > > But naturally, it didn't seem to work, claiming that the children widget > > had no method connect or something such. > > > > Any hint on doing so, or maybe a set_text method could be added to the > > button object ? > > It would not be a good idea if the object contain something else than > a label.... Well, the button is created with GButton#button ~text:"Foo", so we are sure there is at least a label widget in there. Maybe an idea would be for the the button class to have a primary_label or something method which would return the the label it creates. If for whatever reason the label is removed from the button, it would raise not_found maybe, or something such, but i doubt this case happens a lot. Friendly, Sven Luther