GTK+的固定容器管理器---fixed

#include <gtk/gtk.h>

int main(int argc, char *argv[]) {
GtkWidget* window;
GtkWidget* fixed;

GtkWidget* button1;
GtkWidget* button2;

//设置主窗体
gtk_init(&argc, &argv);
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(window), "测试容器管理");
gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
gtk_window_set_default_size(GTK_WINDOW(window), 400, 400);
g_signal_connect_swapped(G_OBJECT(window), "destroy",
G_CALLBACK(gtk_main_quit), NULL);

//设置fixed容器布局管理器
fixed = gtk_fixed_new();
gtk_container_add(GTK_CONTAINER(window), fixed);

//添加按钮
button1 = gtk_button_new_with_label("按钮1");
gtk_fixed_put(GTK_FIXED(fixed), button1, 20, 20);
button2 = gtk_button_new_with_label("按钮2");
gtk_fixed_put(GTK_FIXED(fixed), button2, 20, 80);

//最终显示
gtk_widget_show_all(window);
gtk_main();
return 0;
}

Leave a Reply

Your email address will not be published. Required fields are marked *