So I have to make a simple program in C using GTK for my class. So pretty much a window with 2 buttons, and an exit button below them. Then a popup asking if the user is sure if he wants to exit.
My problem is when I'm compiling, I don't understand why I am getting these errors or how to fix them. Please help me :).
For compiling I use: cc main.c -o win `pkg-config --clfags --libs gtk+-2.0`
(win:2654): Gtk-CRITICAL **: IA__gtk_container_add: assertion `GTK_IS_WIDGET (widget)' failed
(win:2654): Gtk-CRITICAL **: IA__gtk_table_attach: assertion `GTK_IS_TABLE (table)' failed
(win:2654): Gtk-CRITICAL **: IA__gtk_table_attach: assertion `GTK_IS_TABLE (table)' failed
(win:2654): Gtk-CRITICAL **: IA__gtk_widget_show: assertion `GTK_IS_WIDGET (widget)' failed
Code
Code:
#include <gtk/gtk.h>
void day(GtkWidget* w, gpointer data)
{
g_print("The sun comes out during the day.\n");
}
void night(GtkWidget*w, gpointer data)
{
g_print("The moon comes out during the night.\n");
}
gint delete_event(GtkWidget* w, GdkEvent* e, gpointer data)
{
g_print("Please use exit button\n");
return TRUE;
}
void destroy(GtkWidget* w, gpointer data)
{
gtk_main_quit();
}
int main(int argc, char** argv)
{
GtkWidget* win;
GtkWidget* button;
GtkWidget* table;
//////////Window//////////
gtk_init(&argc, &argv);
win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
g_signal_connect(G_OBJECT(win), "delete_event", G_CALLBACK(delete_event), NULL);
g_signal_connect(G_OBJECT(win), "destroy", G_CALLBACK(destroy), NULL);
gtk_container_set_border_width(GTK_CONTAINER(win), 20);
//////////////////////////
/////////Table//////////////
gtk_table_new(3,3,TRUE);
gtk_container_add(GTK_CONTAINER(win), table);
////////////////////////////
/////////////////Day Button//////////////////////
button = gtk_button_new_with_label("Day");
g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(day), NULL);
gtk_table_attach_defaults(GTK_TABLE(table), button, 0, 1, 0, 1);
gtk_widget_show(button);
/////////////////////////////////////////////////
//////////////////////Night Button///////////////////
button = gtk_button_new_with_label("Night");
g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(night), NULL);
//gtk_table_attach_defaults(GTK_TABLE(table), button, 1, 2, 0, 1);
gtk_table_attach_defaults(GTK_TABLE(table), button, 2, 3, 0, 1);
gtk_widget_show(button);
/////////////////////////////////////////////////////
/////////////////Exit Button////////////////////////
////////////////////////////////////////////////////
//////////////////////Table/////////////////////
gtk_widget_show(table);
////////////////////////////////////////////////
gtk_widget_show(win);
gtk_main();
return 0;
}