如何在 GtkWidget 中设置前导空格?正如您在下面的图像中看到的那样,当窗口开始时,用户名/密码小部件离水平线有点远
我的代码:
GtkWidget *window;
GtkWidget *login_label;
GtkWidget *username_label, *password_label;
GtkWidget *username_entry, *password_entry;
GtkWidget *ok_button;
GtkWidget *hbox0, *hbox1, *hbox2, *hbox3;
GtkWidget *vbox;
gtk_init(&argc, &argv);
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(window), "hello");
gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
gtk_window_set_default_size(GTK_WINDOW(window), 200, 300);
g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(gtk_main_quit), NULL);
login_label = gtk_label_new("Login");
username_label = gtk_label_new("Username: ");
password_label = gtk_label_new("Password: ");
username_entry = gtk_entry_new();
password_entry = gtk_entry_new();
gtk_entry_set_visibility(GTK_ENTRY(password_entry), FALSE);
ok_button = gtk_button_new_with_label("Enter");
g_signal_connect(G_OBJECT(ok_button), "clicked", G_CALLBACK(print_username), ok_button);
hbox0 = gtk_hbox_new(TRUE, 5);
hbox1 = gtk_hbox_new(TRUE, 5);
hbox2 = gtk_hbox_new(TRUE, 5);
hbox3 = gtk_hbox_new(TRUE, 5);
vbox = gtk_vbox_new(FALSE, 10);
gtk_box_pack_start(GTK_BOX(hbox0), login_label, TRUE, FALSE, 5);
gtk_box_pack_start(GTK_BOX(hbox1), username_label, TRUE, FALSE, 5);
gtk_box_pack_start(GTK_BOX(hbox1), username_entry, TRUE, FALSE, 5);
gtk_box_pack_start(GTK_BOX(hbox2), password_label, TRUE, FALSE, 5);
gtk_box_pack_start(GTK_BOX(hbox2), password_entry, TRUE, FALSE, 5);
gtk_box_pack_start(GTK_BOX(hbox3), ok_button, FALSE, FALSE, 5);
gtk_box_pack_start(GTK_BOX(vbox), hbox0, FALSE, FALSE, 5);
gtk_box_pack_start(GTK_BOX(vbox), hbox1, FALSE, FALSE, 5);
gtk_box_pack_start(GTK_BOX(vbox), hbox2, FALSE, FALSE, 5);
gtk_box_pack_start(GTK_BOX(vbox), hbox3, FALSE, FALSE, 5);
gtk_container_add(GTK_CONTAINER(window), vbox);
gtk_widget_show_all(window);
gtk_main();