50分求助一个linux下的gtk+程序的困惑
问题描述:随便修改一个按钮长度的大小(gtk_table_attach函数里),都会引起整个界面布局的变化。假定的修改,具体的问题写在代码注释里面,非常希望有人能帮我解答。
程序代码:
#include <gtk/gtk.h> int main (int argc, char *argv[]) { GtkWidget *window; GtkWidget *label; GtkWidget *button1; GtkWidget *button2; GtkWidget *button3; GtkWidget *button4; GtkWidget *button5; GtkWidget *button6; GtkWidget *button7; GtkWidget *table; gtk_init (&argc, &argv); window = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_window_set_title (GTK_WINDOW(window),"计算机学院"); gtk_widget_set_usize (window, 305, 235); gtk_widget_set_uposition(window, 500, 100); table = gtk_table_new(2,15,1); button1 = gtk_button_new_with_label("记录学生成绩"); button2 = gtk_button_new_with_label("删除学生成绩"); button3 = gtk_button_new_with_label("修改学生成绩"); button4 = gtk_button_new_with_label("查询学生成绩"); button5 = gtk_button_new_with_label("保存文件"); button6 = gtk_button_new_with_label("导出文件"); button7 = gtk_button_new_with_label("退出"); label = gtk_label_new("成绩管理系统"); gtk_container_add(GTK_CONTAINER(window), table); gtk_table_attach (GTK_TABLE(table), button1, 1, 15, 1, 2, (GtkAttachOptions)(GTK_FILL), (GtkAttachOptions)(0), 0, 0); gtk_table_attach (GTK_TABLE(table), button2, 1, 15, 2, 3, (GtkAttachOptions)(GTK_FILL), (GtkAttachOptions)(0), 0, 0); gtk_table_attach (GTK_TABLE(table), button3, 1, 15, 3, 4, (GtkAttachOptions)(GTK_FILL), (GtkAttachOptions)(0), 0, 0); gtk_table_attach (GTK_TABLE(table), button4, 1, 15, 4, 5, (GtkAttachOptions)(GTK_FILL), (GtkAttachOptions)(0), 0, 0);//为什么这里6不能设成15?设成15之后整个界面都变了 gtk_table_attach (GTK_TABLE(table), button5, 1, 15, 5, 6, (GtkAttachOptions)(GTK_FILL), (GtkAttachOptions)(0), 0, 0); gtk_table_attach (GTK_TABLE(table), button6, 1, 15, 6, 7, (GtkAttachOptions)(GTK_FILL), (GtkAttachOptions)(0), 0, 0); gtk_table_attach (GTK_TABLE(table), button7, 1, 15, 7, 8, (GtkAttachOptions)(GTK_FILL), (GtkAttachOptions)(0), 0, 0); gtk_table_attach (GTK_TABLE(table), label, 0, 16, 0, 1, (GtkAttachOptions)(GTK_FILL), (GtkAttachOptions)(0), 0, 0); //上面这部分,按钮的长度只要发生变化,都会引起整个界面发生变化,为什么阿?我只想改变一个按钮长度而已。 gtk_widget_show (window); gtk_widget_show (table); gtk_widget_show (button1); gtk_widget_show (button2); gtk_widget_show (button3); gtk_widget_show (button4); gtk_widget_show (button5); gtk_widget_show (button6); gtk_widget_show (button7); gtk_widget_show (label); gtk_main(); return 0; }