Re: About gtk_label_set_text()
- From: learfox furry ao net
- To: Antonio Martínez Álvarez <newton retemail es>
- Cc: GTK Application Development List <gtk-app-devel-list gnome org>
- Subject: Re: About gtk_label_set_text()
- Date: Sat, 24 Feb 2001 13:46:56 -0800 (PST)
Hello list:
I'm trying to write a simple application. One button with label "1", and
every time the user do a click on it, the label must increase the label
by one. 1 --> 2 --> 3 etc...
I have found that I only can use a const string
(gtk_label_set_text(label, "anything") but no way to do what I say. How
can I do that.
Hmm, how about this, make a callback for "clicked" where the data passed
is the label widget. Like this;
static void my_button_cb(GtkWidget *button, gpointer data)
{
int number;
const char *cstrptr;
char *strptr;
char tmp_str[256];
GtkLabel *label = (GtkLabel *)data;
if(label == NULL)
return;
/* Get label, assumed format is any numerical value. */
cstrptr = (const char *)gtk_label_get_text(label);
if((cstrptr != NULL) ? isdigit(*cstrptr) : 0)
{
/* Get the old label string, convert it to a number and
* increment by 1.
*/
number = atoi(cstrptr) + 1;
/* Set the new label. */
sprintf(tmp_str, "%i", number);
gtk_label_set_text(label, (const char *)tmp_str);
}
return;
}
I think this should work! When you attach the signal, make sure you
pass the label widget as the client data pointer.
--
Sincerely, ,"-_ \|/
-Capt. Taura M. , O=__ --X--
..__ ,_JNMNNEO=_ /|\
OMNOUMmnne. {OMMNNNEEEEOO=_
UOOOBIOOOEOMMn. 'LONMMMMNNEEEOOO=.__..,,..
UUOOEUUOOOOOOOObe '"=OMMMMWNEEEOOOOO,"=OEEEOO=,._
OOUUUIEEIOONNOIUbe. "7OMMMMNNNNNWWEEEEOOOOOO" "'.
EEBNNMMMNWNWWEEIMMNe. __ 7EMMMNNNNNWWWEEEEEEEOO. " .
NNMMMMWWWMMMWEINMMMNn "=BBEEEEMMMMMMMMNNNWWWEEOOOOO=._ .
http://furry.ao.net/~learfox/
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]