Re: Help spinbuttons, Paulo Silva



On Thu, 2015-04-09 at 23:17 +0930, Roger Matthews wrote:
Hi Paulo, or anybody else interested in helping,
I've read chapter 2 of Foundations of GTK+ Development concerning
signals and callback functions as suggested (see below) but am still
getting this error:

Hello,

I think you used wrong parameters for your callback function: Try this
modified example:

#include <stdio.h>
#include <gtk/gtk.h>
 
static void get_new_number(GtkWidget *widget, gpointer data)
{
        float value;
  value = gtk_spin_button_get_value(GTK_SPIN_BUTTON(widget));
        printf("value = %f\n", value);
}
 
int main(int argc, char *argv[])
{
GtkWidget *window, *spin_float;
GtkAdjustment *float_pt;
 
gtk_init (&argc, &argv);
 
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_widget_set_size_request (window, 150, 100);
 
float_pt = GTK_ADJUSTMENT (gtk_adjustment_new (0.5, 0.0, 1.0, 0.1, 0.5,
0.5));
 
spin_float = gtk_spin_button_new (float_pt, 0.1, 1);
 
gtk_container_add (GTK_CONTAINER (window), spin_float);
gtk_widget_show_all (window);
 
g_signal_connect (spin_float, "value-changed", G_CALLBACK
(get_new_number), NULL);
  
gtk_main ();
 
 return 0;
}

$ gcc t.c -o test `pkg-config --cflags --libs gtk+-3.0`
$ ./test 
value = 0.400000
value = 0.300000
value = 0.200000

Please note that there was no callback to close the window in your
example, so we have to press CTRL C to terminate the program. Generally,
if you already have the Krause book, you may find examples for Spin
Buttons too, maybe not printed completely, but full code should be
available in Internet somewhere. But it is GTK2 still.

And note that you do not have to use C language for GTK toolkit -- there
are bindings available fpr many other languages, some have even
tutorials, i.e. Ruby or Python. These may be easier for beginners.






[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]