How do I set the leading spaces in a GtkWidget? as you can see into below imagem, username/password widgets are a bit away from horizontal line when the window begins

My code:
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();
A
GtkGridinside of aGtkDialogis probably more appropriate for the layout you are trying to achieve, however, let me at least help with your code as it is now.For the packing, I assume you want the
GtkLabelwidgets to be a fixed width, left-aligned. TheGtkEntrywidgets would fill up the rest of the horizontal space.First, you can control the “alignment” of the text within a
GtkLabel. Since aGtkLabelis aGtkMisc, you can use that to align the text. The alignment is a fraction where0.0is all the way to the left/top and1.0all the way to the right/bottom.Assuming you are using GTK+ 3, you probably should ditch the deprecated
gtk_hbox_new()andgtk_vbox_new()functions in favor ofgtk_box_new(). I’ve found there are often unexpected results using those deprecated functions in GTK+ 3.Finally, you can change the packing so that the labels do not expand, but the entries do.
While it’s a little bit out of date, you may want to read How Packing Effects the Layout from my GTK+ tutorial. By playing with packing properties in Glade you can quickly test your layouts before hard-coding them in C.
Also note that as of GTK+ 3, the
"halign","valign","hexpand"and"vexpand"are now preferred over the"expand"and"fill"properties.Edit
Here is a “better” way to do it with a
GtkGridwhich handles the width-for-height geometry of GTK+ 3 a little better and ensures you have both rows and columns.First, set the
hexpandproperty of the entry widgets (as opposed to “packing” them into a box with expand):Next, attach all of the widgets to a grid. You can span the “login” label and the “ok” button across multiple columns:
The arguments to
gtk_grid_attachspecify the placement, width, and height (in cells, not pixels) for each widget. Check out the API docs for GtkGrid for details.