#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    26
    Rep Power
    0

    How To Correctly Set A Button Label In Gtk


    I am trying to make a tictactoe program in gtk but when i click a button it doesnt chane the label of the button to O
    I get no errors or warnings when i compile but i do get errors in the CMD i get 9 that they all say

    (TicTacToe.exe:3636): GLib-GObject-WARNING **: gsignal.c:2275: signal `clicked'
    is invalid for instance `01360008'

    Thank you for your help

    Here is my code

    Code:
    #include <gtk/gtk.h>
    char buf[200];
    
    void B0(GtkWidget *window,gpointer b)
    {
        static int count=0;
    
        if(count==0)
        {
            gtk_button_set_label(GTK_BUTTON(b),"O");
            count++;
        }
    }
    void B1(GtkWidget *window,gpointer b1)
    {
        static int count=0;
    
        if(count==0)
        {
            gtk_button_set_label(GTK_BUTTON(b1),"O");
            count++;
        }
    }
    void B2(GtkWidget *window,gpointer b2)
    {
        static int count=0;
    
        if(count==0)
        {
            gtk_button_set_label(GTK_BUTTON(b2),"O");
            count++;
        }
    }
    void B3(GtkWidget *window,gpointer b3)
    {
        static int count=0;
    
        if(count==0)
        {
            gtk_button_set_label(GTK_BUTTON(b3),"O");
            count++;
        }
    }
    void B4(GtkWidget *window,gpointer b4)
    {
        static int count=0;
    
        if(count==0)
        {
            gtk_button_set_label(GTK_BUTTON(b4),"O");
            count++;
        }
    }
    void B5(GtkWidget *window,gpointer b5)
    {
        static int count=0;
    
        if(count==0)
        {
            gtk_button_set_label(GTK_BUTTON(b5),"O");
            count++;
        }
    }
    void B6(GtkWidget *window,gpointer b6)
    {
        static int count=0;
    
        if(count==0)
        {
            gtk_button_set_label(GTK_BUTTON(b6),"O");
            count++;
        }
    }
    void B7(GtkWidget *window,gpointer b7)
    {
        static int count=0;
    
        if(count==0)
        {
            gtk_button_set_label(GTK_BUTTON(b7),"O");
            count++;
        }
    }
    void B8(GtkWidget *window,gpointer b8)
    {
        static int count=0;
    
        if(count==0)
        {
            gtk_button_set_label(GTK_BUTTON(b8),"O");
            count++;
        }
    }
    int main(int argc,char *argv[])
    {
        GtkWidget *window,*b,*b1,*b2,*b3,*b4,*b5,*b6,*b7,*b8,*fixed;
    
        gtk_init(&argc,&argv);
        window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
        gtk_window_set_position(GTK_WINDOW(window),GTK_WIN_POS_CENTER);
        gtk_window_set_default_size(GTK_WINDOW(window),250,250);
        gtk_window_set_title(GTK_WINDOW(window),"Tic");
        int Y=50,X=50;
        fixed = gtk_fixed_new();
        gtk_container_add(GTK_CONTAINER(window),fixed);
    
        b = gtk_button_new_with_label("");
        gtk_widget_set_size_request(b,50,50);
        gtk_fixed_put(GTK_FIXED(fixed),b,Y,X);
    
         b1 = gtk_button_new_with_label("");
        gtk_widget_set_size_request(b1,50,50);
        gtk_fixed_put(GTK_FIXED(fixed),b1,Y+50,X);
    
         b2 = gtk_button_new_with_label("");
        gtk_widget_set_size_request(b2,50,50);
        gtk_fixed_put(GTK_FIXED(fixed),b2,Y+100,X);
    
        b3= gtk_button_new_with_label("");
        gtk_widget_set_size_request(b3,50,50);
        gtk_fixed_put(GTK_FIXED(fixed),b3,Y,X+50);
    
         b4 = gtk_button_new_with_label("");
        gtk_widget_set_size_request(b4,50,50);
        gtk_fixed_put(GTK_FIXED(fixed),b4,Y+50,X+50);
    
         b5 = gtk_button_new_with_label("");
        gtk_widget_set_size_request(b5,50,50);
        gtk_fixed_put(GTK_FIXED(fixed),b5,Y+100,X+50);
    
         b6 = gtk_button_new_with_label("");
        gtk_widget_set_size_request(b6,50,50);
        gtk_fixed_put(GTK_FIXED(fixed),b6,Y,X+100);
    
         b7 = gtk_button_new_with_label("");
        gtk_widget_set_size_request(b7,50,50);
        gtk_fixed_put(GTK_FIXED(fixed),b7,Y+50,X+100);
    
         b8 = gtk_button_new_with_label("");
        gtk_widget_set_size_request(b8,50,50);
        gtk_fixed_put(GTK_FIXED(fixed),b8,Y+100,X+100);
    
        g_signal_connect(window,"destroy",G_CALLBACK(gtk_main_quit),NULL);
        g_signal_connect(window,"clicked",G_CALLBACK(B0),b);
        g_signal_connect(window,"clicked",G_CALLBACK(B1),b1);
        g_signal_connect(window,"clicked",G_CALLBACK(B2),b2);
        g_signal_connect(window,"clicked",G_CALLBACK(B3),b3);
        g_signal_connect(window,"clicked",G_CALLBACK(B4),b4);
        g_signal_connect(window,"clicked",G_CALLBACK(B5),b5);
        g_signal_connect(window,"clicked",G_CALLBACK(B6),b6);
        g_signal_connect(window,"clicked",G_CALLBACK(B7),b7);
        g_signal_connect(window,"clicked",G_CALLBACK(B8),b8);
    
        gtk_widget_show_all(window);
        gtk_main();
    }
  2. #2
  3. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,904
    Rep Power
    481
    Would have been nice if you'd included compilation instructions. My batteries have run down---the laptop's and my soul's. I might not return to this project but for those of you on linux with gtk properly installed, I named the source c.c and built/ran the program making heavy use of pkg-config with command
    Code:
    a=./c && make -k "CFLAGS=$( pkg-config --cflags gtk+-3.0 )" "LOADLIBES=$( pkg-config --libs gtk+-3.0 )" $a && $a --gtk-debug=all
    The program flickers my screen, and on mouse-over various regions flash red. There is a 9x9 grid.

    Dave.

    PS. Source for the compilation instructions come from a gtk code I previously wrote which, when studied might lead to an answer or more likely to confusion:
    http://rosettacode.org/wiki/Honeycombs#C
    [code]Code tags[/code] are essential for python code and Makefiles!

IMN logo majestic logo threadwatch logo seochat tools logo