#include <gtk/gtk.h>
static GtkWidget *createWindow(void)
{
GtkWidget *window;
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_default_size(GTK_WINDOW(window), 200, 200);
gtk_window_set_title(GTK_WINDOW(window), "GTK");
gtk_container_set_border_width(GTK_CONTAINER(window), 50);
g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);
return window;
}
void user_function (GtkWidget *togglebutton, gpointer user_data)
{
if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(togglebutton)))
g_print("The toggle button was clicked\n");
else
g_print("The toggle button was release\n");
}
int main(void)
{
GtkWidget *window;
GtkWidget *tgl_button;
gtk_init(NULL, NULL);
window = createWindow();
tgl_button = gtk_toggle_button_new();
g_signal_connect(tgl_button, "toggled", G_CALLBACK(user_function), NULL);
gtk_container_add(GTK_CONTAINER(window), tgl_button);
gtk_widget_show_all(window);
gtk_main();
}
- 运行效果