To: lablgtk at kaba.or.jp Subject: Re: changing the text of a button ? From: Remi Vanicat Date: Thu, 09 Oct 2003 14:36:36 +0200 In-Reply-To: Remi Vanicat's message of "(unknown date)" Message-ID: <87ismyio4r.dlv at wanadoo.fr> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-15 Content-Transfer-Encoding: 8bit Sender: Vanicat Remi Remi Vanicat writes: > 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" I've forgot one other cleaner way : When you build your button, don't give it a label string at construction time, but add to it a label (widget) afterward. You have then directly the good object with the good type. -- Rémi Vanicat remi.vanicat@laposte.net