#include <gtk/gtk.h>
#include <glib/gstdio.h>
#include <stdio.h>
#include <stdlib.h>
GtkBuilder *builder;
GObject *window;
GObject *button;
GObject *button2;
static void
print_hello (GtkWidget *widget,
gpointer data)
{
g_print ("Hello World\n");
printf("fuckyou\n");
char *buffer = "OK";
gtk_button_set_label(GTK_BUTTON(button),buffer);
}
static void
print_hello2 (GtkWidget *widget,
gpointer data)
{
g_print ("Hello World\n");
gtk_button_set_label(GTK_BUTTON(widget),"fuckyou");
}
static void
activate (GtkApplication *app,
gpointer user_data)
{
/* Construct a GtkBuilder instance and load our UI description */
builder = gtk_builder_new ();
gtk_builder_add_from_file (builder, "builder.ui", NULL);
/* Connect signal handlers to the constructed widgets. */
window = gtk_builder_get_object (builder, "window");
gtk_window_set_application (GTK_WINDOW (window), app);
button = gtk_builder_get_object (builder, "button1");
button2 = gtk_builder_get_object (builder, "button2");
g_signal_connect (button, "clicked", G_CALLBACK (print_hello2), button2);
g_signal_connect (button2, "clicked", G_CALLBACK (print_hello), NULL);
gtk_widget_set_visible (GTK_WIDGET (window), TRUE);
/* We do not need the builder any more */
g_object_unref (builder);
}
int
main (int argc,
char *argv[])
{
#ifdef GTK_SRCDIR
g_chdir (GTK_SRCDIR);
#endif
GtkApplication *app = gtk_application_new ("org.gtk.example", G_APPLICATION_DEFAULT_FLAGS);
g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
int status = g_application_run (G_APPLICATION (app), argc, argv);
g_object_unref (app);
return status;
}
builder.ui
<?xml version='1.0' encoding='UTF-8'?>
<!-- Created with Cambalache 0.17.0 -->
<interface>
<!-- interface-name builer.ui -->
<requires lib="gtk" version="4.12"/>
<object class="GtkWindow" id="window">
<child>
<object class="GtkFixed" id="fixed">
<child>
<object class="GtkButton" id="button1">
<property name="label">button1</property>
<property name="margin-start">24</property>
<property name="margin-top">20</property>
</object>
</child>
<child>
<object class="GtkButton" id="button2">
<property name="label">button2</property>
<property name="margin-start">120</property>
<property name="margin-top">20</property>
</object>
</child>
</object>
</child>
</object>
</interface>