Textbox with a label in a GTK+ program - c

I am new to GTK+ programming.I wrote a simple GTK+ program where i display a label and a textbox in a window, the label should be to the left of the textbox and i should be able to specify the horizontal length of the textbox. Below is my code so far,the program runs fine but im unable to align the label to the left of the textbox and also set the textbox horizontal length.
#include <stdio.h>
#include <stdlib.h>
#include <gtk/gtk.h>
static void destroy(GtkWidget *widget,gpointer data)
{
gtk_main_quit ();
}
int main (int argc, char *argv[])
{
GtkWidget *window,*table,*label,*entry;
gtk_init(&argc, &argv);
void initialize_window(GtkWidget *);
//Create the main window
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
initialize_window(window);
gtk_widget_show(window);
/* Create a 1x2 table */
table = gtk_table_new (1, 2, TRUE);
gtk_container_add (GTK_CONTAINER (window), table);
gtk_widget_show (table);
/* create a new label. */
label = gtk_label_new ("Enter some text: ");
gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
gtk_table_attach_defaults (GTK_TABLE (table),label, 0, 1, 0, 1);
gtk_widget_show (label);
//create a text box
entry = gtk_entry_new ();
gtk_entry_set_max_length (GTK_ENTRY (entry),0);
gtk_table_attach_defaults (GTK_TABLE (table),entry, 0, 1, 0, 1);
gtk_widget_show (entry);
gtk_main ();
return 0;
}
void initialize_window(GtkWidget *window)
{
gtk_window_set_title(GTK_WINDOW(window),"My Window"); //Set window title
gtk_window_set_default_size (GTK_WINDOW (window), 400, 200); //Set default size for the window
g_signal_connect (window, "destroy",G_CALLBACK (destroy), NULL); //End application when close button clicked
}
How can i fix this problem ?
Please help
Thank You.

You messed with the table position and don't set aligin if you do not know what it does, it may be a bit missleading.
Here is working code (I think this is what you wanted):
#include <stdio.h>
#include <stdlib.h>
#include <gtk/gtk.h>
static void destroy(GtkWidget *widget, gpointer data)
{
gtk_main_quit ();
}
static void initialize_window(GtkWidget* window)
{
gtk_window_set_title(GTK_WINDOW(window),"My Window"); //Set window title
gtk_window_set_default_size (GTK_WINDOW (window), 400, 200); //Set default size for the window
g_signal_connect (window, "destroy", G_CALLBACK (destroy), NULL); //End application when close button clicked
}
int main (int argc, char *argv[])
{
GtkWidget *window,*table,*label,*entry;
gtk_init(&argc, &argv);
//Create the main window
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
initialize_window(window);
/* Create a 1x2 table */
table = gtk_table_new (1, 2, TRUE);
gtk_container_add (GTK_CONTAINER (window), table);
/* create a new label. */
label = gtk_label_new ("Enter some text:" );
//gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
gtk_table_set_homogeneous(GTK_TABLE (table), TRUE);
gtk_table_attach_defaults (GTK_TABLE (table), label, 1, 2, 0, 1);
//create a text box
entry = gtk_entry_new ();
gtk_entry_set_max_length (GTK_ENTRY (entry),0);
gtk_table_attach_defaults (GTK_TABLE (table), entry, 0, 1, 0, 1);
gtk_widget_show_all(window);
gtk_main ();
return 0;
}

For alignment one can use hbox for horizontal arrangement or vbox for vertical arrangement.

Related

GTK3 resize attempt grows window exponentially

I have a C GTK3 program that has a notebook with two images. I want to be able to grab the corner of the window and adjust the size of the image currently displayed. What I currently have is a program that once started, the window keeps growing until I kill it from the terminal using ctrl-c. I put a sleep call in the callback to slow it down, but it still grows. How do I stop the window from growing unless I "grab" a corner of the window and adjust it myself?
#include <stdio.h>
#include <gtk/gtk.h>
#include <gdk-pixbuf/gdk-pixbuf.h>
GtkWidget *notebook;
gboolean resize_image(GtkWidget *widget, GdkRectangle *allocation,
gpointer user_data)
{
int w,h, pagenum;
GdkPixbuf *pxbscaled;
GtkWidget *image;
GdkPixbuf *pixbuf;
pagenum = gtk_notebook_get_current_page (GTK_NOTEBOOK(notebook));
image = gtk_notebook_get_nth_page (GTK_NOTEBOOK(notebook), pagenum);
// GtkImageType image_type = gtk_image_get_storage_type
// (GTK_IMAGE(image));
pixbuf = gtk_image_get_pixbuf(GTK_IMAGE(image));
h = allocation->height;
w = (gdk_pixbuf_get_width(pixbuf) * h) / gdk_pixbuf_get_height(pixbuf);
pxbscaled = gdk_pixbuf_scale_simple(pixbuf, w, h, GDK_INTERP_BILINEAR);
printf("Allocation height %d width %d.\n", h, w);
gtk_image_set_from_pixbuf(GTK_IMAGE(image), pxbscaled);
g_object_unref (pxbscaled);
sleep(2);
return FALSE;
}
static gboolean delete( GtkWidget *widget,
GtkWidget *event,
gpointer data )
{
gtk_main_quit ();
return FALSE;
}
int main( int argc,
char *argv[] )
{
GtkWidget *window;
GtkWidget *button;
GtkWidget *table;
GtkWidget *label;
GtkWidget *image;
int i;
char bufferl[32];
gtk_init (&argc, &argv);
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
// gtk_widget_set_size_request (GTK_WIDGET(window), 800, 480);
g_signal_connect (window, "delete-event",
G_CALLBACK (delete), NULL);
gtk_container_set_border_width (GTK_CONTAINER (window), 10);
table = gtk_grid_new ();
gtk_container_add (GTK_CONTAINER (window), table);
/* Create notebook, place position of tabs */
notebook = gtk_notebook_new ();
gtk_notebook_set_tab_pos (GTK_NOTEBOOK (notebook), GTK_POS_TOP);
gtk_grid_attach (GTK_GRID (table), notebook, 0, 6, 3, 3);
gtk_widget_show (notebook);
/* Append pages to the notebook */
for (i = 0; i < 2; i++) {
sprintf(bufferl, "Page %d", i + 1);
if (i == 0) {
image = gtk_image_new_from_file("image1.jpg");
} else {
image = gtk_image_new_from_file("image2.jpg");
}
gtk_widget_set_halign(image, GTK_ALIGN_START);
gtk_widget_set_valign(image, GTK_ALIGN_START);
g_signal_connect(window, "size-allocate",
G_CALLBACK(resize_image), NULL);
label = gtk_label_new (bufferl);
gtk_notebook_append_page (GTK_NOTEBOOK(notebook),
image, label);
}
/* Create a close button */
button = gtk_button_new_with_label ("close");
g_signal_connect (button, "clicked",
G_CALLBACK (delete), NULL);
gtk_grid_attach (GTK_GRID (table), button, 0, 10, 1, 1);
gtk_widget_show_all (window);
gtk_main ();
return 0;
}
A user will need to provide image1.jpg and image2.jpg. Edit out the sleep call will result in the program filling the screen extremely quickly.
EDIT: I have also asked this question on the gtk mailing list.
The window with the image was growing because I was applying the size of the window to the image. Hence the image got larger and thus made the window get larger. Which continued in an endless progression, the "size-allocate" signal was constantly being called.
I fixed it by limiting the allocation height in the call back, by multiplying it by 0.75.
Now I can expand and contract the window with ease and it does not grow out of control.
The image does get ugly quite quickly, but that is another problem.

How to send multiple entrys to function - GTK

I have developed a financial calculator in c - Black & Scholes. My teacher wants me to implement a GUI to this and he suggested GTK. Due to my poor knowledge in c (java programmer from the start) this is almost too much for me at the moment because the deadline is in 4 hours. But after hard work and good help here on stackoverflow I think I have a chanche to make it!. But right now there is one irritating obstacle to overide -
That is to pass more than one entry to a method. In short - there are five inputfields and what I want is to send all these via g_signal_connect_swapped to a method where the invoked string i extracted. The thing is that I am able to do this (thanks to help) as long as there are only one string (one entry). But how do I send all these entrys to the function?
I have tried to declare a vector without success. It wont even compile due to errors.
static GtkWidget entry[5]
Since an array is a pointer (to the first element) it should work - but not!
And more strange - I had another idea - instead of sending the entrys I tried to extract the string value in the main-method - exaxtly the same syntax as in the function - but without succes. The value is null.
const gchar *text;
text = gtk_entry_get_text(GTK_ENTRY (entry_a));
printf ("Result: %s\n", text);
the above snippet works as expexted in the function - but not in the main-function. Why???
Hope you understand my question - here follows the code that generates the GUI. The code is without error - that is where I send ONE entry-value to the callback-function.
#include <stdio.h>
#include <stdlib.h>
#include <gtk/gtk.h>
static GtkWidget *asset_label;
static GtkWidget *frame;
static GtkWidget *entry_a, *entry_s, *entry_v, *entry_t, *entry_r;
static GtkWidget *label_a, *label_s, *label_v, *label_t, *label_r;
static GtkWidget *window, *result_label, *button;
static GtkWidget *table;
static void entry_Submit(GtkWidget *entry, GtkWidget *widget) {
const gchar *text;
text = gtk_entry_get_text(GTK_ENTRY (entry_a));
printf ("Result: %s\n", text);
gtk_widget_destroy(GTK_WIDGET(label_a));
label_a = gtk_label_new (text);
gtk_grid_attach (GTK_GRID (table), label_a, 1, 0, 1, 1);
gtk_widget_show(label_a);
}
static void destroy(GtkWidget *widget, gpointer data) {
gtk_main_quit ();
}
static void initialize_window(GtkWidget* window) {
gtk_window_set_title(GTK_WINDOW(window),"My Window"); //Set window title
gtk_window_set_default_size (GTK_WINDOW (window), 400, 200); //Set default size for the window
g_signal_connect (window, "destroy", G_CALLBACK (destroy), NULL); //End application when close button clicked
}
int main (int argc, char *argv[]) {
//GtkWidget *window,*table,*label, *button;
gtk_init(&argc, &argv);
//Create the main window
//window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
//initialize_window(window);
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_widget_set_size_request (GTK_WIDGET (window), 300, 300);
gtk_window_set_title (GTK_WINDOW (window), "FINANCIAL CALCULATOR");
g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL);
g_signal_connect_swapped (window, "delete-event", G_CALLBACK (gtk_widget_destroy), window);
/* Create a 1x2 table */
table = gtk_grid_new ();
gtk_container_add (GTK_CONTAINER (window), table);
//create a text box (asset price)
entry_a = gtk_entry_new ();
gtk_grid_attach (GTK_GRID (table), entry_a, 0, 0, 1, 1);
// create a new label.
label_a = gtk_label_new (" ASSET PRICE" );
gtk_grid_attach (GTK_GRID (table), label_a, 1, 0, 1, 1);
//create a text box (strike price)
entry_s = gtk_entry_new ();
gtk_grid_attach (GTK_GRID (table), entry_s, 0, 1, 1, 1);
// create a new label.
label_s = gtk_label_new (" STRIKE PRICE" );
gtk_grid_attach (GTK_GRID (table), label_s, 1, 1, 1, 1);
//create a text box (time to maturity)
entry_t = gtk_entry_new ();
gtk_grid_attach (GTK_GRID (table), entry_t, 0, 2, 1, 1);
// create a new label.
label_t = gtk_label_new (" TIME TO MATURITY" );
gtk_grid_attach (GTK_GRID (table), label_t, 1, 2, 1, 1);
//create a text box (volatility)
entry_v = gtk_entry_new ();
gtk_grid_attach (GTK_GRID (table), entry_v, 0, 3, 1, 1);
// create a new label.
label_v = gtk_label_new (" VOLATILITY" );
gtk_grid_attach (GTK_GRID (table), label_v, 1, 3, 1, 1);
//create a text box (interest rate)
entry_r = gtk_entry_new ();
gtk_grid_attach (GTK_GRID (table), entry_r, 0, 4, 1, 1);
// create a new label.
label_r = gtk_label_new (" INTEREST RATE" );
gtk_grid_attach (GTK_GRID (table), label_r, 1, 4, 1, 1);
button = gtk_button_new_with_label("Calculate");
g_signal_connect_swapped (button, "clicked", G_CALLBACK (entry_Submit), entry_a);
gtk_grid_attach (GTK_GRID (table), button, 0, 5, 2, 1);
gtk_widget_show_all(window);
gtk_main ();
return 0;
}
these are the errors when I declare an array of GtkWidget
1) In the entry_submit callback-function () where I declare the following:
text = gtk_entry_get_text(GTK_ENTRY (entry[0]));
compile error: error: subscripted value is neither array nor pointer nor vector
2) In the main function where I declare the following:
entry[0] = gtk_entry_new ();
error: incompatible types when assigning to type 'GtkWidget' from type 'struct GtkWidget *'
A pointer to pointer is the answer and at the same to use malloc since I declare the GtkWidget in the main-function.
GtkWidget **entry;
entry = malloc(5 * sizeof(GtkWidget));
entry[0] = entry_a;
entry[1] = entry_s;
entry[2] = entry_t;
entry[3] = entry_v;
entry[4] = entry_r;
g_signal_connect_swapped (button, "clicked", G_CALLBACK (entry_Submit), entry);
and the function
static void entry_Submit(GtkWidget **entry, GtkWidget *widget) {
GtkWidget *entry_ptr_a = entry[0];
GtkWidget *entry_ptr_s = entry[1];
GtkWidget *entry_ptr_t = entry[2];
GtkWidget *entry_ptr_v = entry[3];
GtkWidget *entry_ptr_r = entry[4];
const gchar *a, *s, *t, *v, *r;
a = gtk_entry_get_text(GTK_ENTRY (entry_ptr_a));
s = gtk_entry_get_text(GTK_ENTRY (entry_ptr_s));
t = gtk_entry_get_text(GTK_ENTRY (entry_ptr_t));
v = gtk_entry_get_text(GTK_ENTRY (entry_ptr_v));
r = gtk_entry_get_text(GTK_ENTRY (entry_ptr_r));
printf ("Result: %s , %s, %s, %s, %s\n", a, s, t, v, r);
}

pass string from inputfield to function fails - GTK c-language

I have one issue with gtk in c . I tried to follow the tutorial but I am not able to pass a text-entry to a function when one clicks on the button in the widget.
The code compiles fine but when I press the button I get several warnings and the string from text-entry that was supposed to be printed are null
What did I do wrong?
#include <stdio.h>
#include <stdlib.h>
#include <gtk/gtk.h>
static GtkWidget *asset_label;
static GtkWidget *frame;
static GtkWidget *entry;
static void entry_Submit(GtkWidget *widget, GtkWidget *entry)
{
const gchar *text = gtk_entry_get_text(GTK_ENTRY (entry));
printf ("Result: %s\n", text);
gtk_widget_destroy(GTK_WIDGET(asset_label));
asset_label = gtk_label_new (text);
gtk_container_add (GTK_CONTAINER (frame), asset_label);
gtk_widget_show_all(frame);
}
static void destroy(GtkWidget *widget, gpointer data)
{
gtk_main_quit ();
}
static void initialize_window(GtkWidget* window)
{
gtk_window_set_title(GTK_WINDOW(window),"My Window"); //Set window title
gtk_window_set_default_size (GTK_WINDOW (window), 400, 200); //Set default size for the window
g_signal_connect (window, "destroy", G_CALLBACK (destroy), NULL); //End application when close button clicked
}
int main (int argc, char *argv[])
{
GtkWidget *window,*table,*label, *button;
gtk_init(&argc, &argv);
//Create the main window
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
initialize_window(window);
/* Create a 1x2 table */
table = gtk_table_new (3, 3, TRUE);
gtk_container_add (GTK_CONTAINER (window), table);
/* create a new label. */
label = gtk_label_new ("Enter some text:" );
//gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
gtk_table_set_homogeneous(GTK_TABLE (table), TRUE);
gtk_table_attach_defaults (GTK_TABLE (table), label, 1, 2, 0, 1);
//create a text box
entry = gtk_entry_new ();
//gtk_entry_set_text (GTK_ENTRY (entry), "");
gtk_entry_set_max_length (GTK_ENTRY (entry),0);
gtk_table_attach_defaults (GTK_TABLE (table), entry, 0, 1, 0, 1);
button = gtk_button_new_with_label("Calculate");
g_signal_connect_swapped (button, "clicked", G_CALLBACK (entry_Submit), entry);
gtk_table_attach_defaults (GTK_TABLE (table), button, 0, 2, 1, 2);
//gtk_widget_show (button);
gtk_widget_show_all(window);
gtk_main ();
return 0;
}
And when the button is clicked I get this result:
Result: (null)
There is a problem in the callback or the way you are registering the callback (as fixing either one of them should fix your problem).
By default the clicked callback takes GtkButton as the first parameter and gpointer data as the second. By using g_signal_connect_swapped you are saying that in the callback function, the parameters will be swapped i.e., the first parameter will be gpointer data (GtkEntry in your code) and second GtkButton. But in your callback function you are treating second parameter entry which is in fact GtkButton as GtkEntry. Either use g_signal_connect instead of g_signal_connect_swapped or use the first parameter widget as GtkEntry in your callback function.
Side note: Regarding the warning, if the code which you have posted is the full code then in the callback function entry_Submit during first execution asset_label is null and thus gtk_widget_destroy(GTK_WIDGET(asset_label)); will throw a warning. Also, frame is unassigned before use in the callback function.
Hope this helps!

GTK+ How to draw into a drawing area

I would like to draw some lines (actually a sine wave) inside a gtk+ cairo drawing area but I can't figure out a way to do that.
So my code first defines the drawing area which has a callback to a function that draws a white background into the drawing area itself...at this point I would like to start drawing a piece of the sin wave after each time the START button is pressed (the button has a callback to the drawing function)....
So first of all..would it be possible to do that??Am I missing something?
Thanks.
#include <cairo.h>
#include <gtk/gtk.h>
int x = 0;
int x_old = 0;
float value = 0;
float value_old = 0;
GtkWidget *button = NULL;
GtkWidget *window = NULL;
GtkWidget *area = NULL;
GtkWidget *table = NULL;
static gboolean load_interface(GtkWidget *widget)
{
cairo_t *cr;
cr = gdk_cairo_create(area->window);
cairo_set_source_rgb(cr, 1, 1, 1);
cairo_rectangle(cr, 0, 0, 900, 400);
cairo_fill(cr);
}
void draw(GtkWidget *widget)
{
cairo_t *cr;
cr = gdk_cairo_create(widget->window);
x_old = x;
x = x + 15;
value_old = value;
value = value + 0.25;
cairo_set_source_rgb(cr, 0, 0, 0);
cairo_set_line_width (cr, 1);
cairo_move_to(cr, x_old, 100 + (sin(value_old))*50);
cairo_line_to(cr, x, 100 + (sin(value))*50);
cairo_stroke(cr);
}
int main (int argc, char *argv[])
{
g_log_set_handler ("Gtk", G_LOG_LEVEL_WARNING, (GLogFunc) gtk_false, NULL);
gtk_init (&argc, &argv);
g_log_set_handler ("Gtk", G_LOG_LEVEL_WARNING, g_log_default_handler, NULL);
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_container_set_border_width (GTK_CONTAINER (window), 3);
gtk_window_set_title (GTK_WINDOW (window), "Draw");
gtk_window_set_position (GTK_WINDOW (window), GTK_WIN_POS_CENTER);
gtk_widget_realize (window);
g_signal_connect (window, "destroy", gtk_main_quit, NULL);
table = gtk_table_new (10, 10, TRUE);
gtk_table_set_col_spacings(GTK_TABLE(table),10);
gtk_table_set_row_spacings(GTK_TABLE(table),5);
gtk_container_add (GTK_CONTAINER (window), table);
area = gtk_drawing_area_new();
gtk_signal_connect (GTK_OBJECT(area), "event", G_CALLBACK (load_interface), (gpointer)area);
gtk_table_attach_defaults (GTK_TABLE(table), area, 1, 10, 0, 10);
button = gtk_button_new_from_stock ("START");
g_signal_connect (G_OBJECT (button), "clicked", G_CALLBACK (draw), (gpointer) window);
gtk_table_attach_defaults (GTK_TABLE(table), button, 0, 1, 0, 1);
gtk_widget_show_all (window);
gtk_main ();
return 0;
}
All your drawing should happen in the drawing area drawing event, called expose-event for GTK2 and draw in GTK3. In response to the button being clicked, you just change some values that you will reuse to compute the whole scene drawn. Once you changed these values, you just invalidate the drawing area to force it being redrawn, calling gtk_widget_queue_draw on the drawing area. And that's it.
If the scene is expensive to draw, remember using cairo clipping functions to improve performance by drawing only what has changed. Use then gtk_widget_queue_draw_area instead of gtk_widget_queue_draw, to give a hint about the zone that has changed and needs to be redrawn.
See GtkDrawingArea documentation.
BTW, don't use casts to GTK_OBJECT (deprecated), use G_OBJECT instead. This makes porting to GTK3 easier.
g_signal_connect() the expose-event.

gtk 3.4 resize widget and label attached to entry widget

I'm trying to give a GTK+3 gui to a my future project (client FTP) but I've some problems.
This is my first code:
#include <gtk/gtk.h>
/* When "connect" button is clicked a message will appear */
static void print_hello (GtkWidget *widget, gpointer data)
{
g_print ("Connect button clicked\n");
}
int main (int argc, char *argv[]){
/* Declare widgets */
GtkWidget *window;
GtkWidget *grid;
GtkWidget *button;
GtkWidget *u_name;
GtkWidget *h_name;
GtkWidget *pass;
GtkWidget *label_user;
GtkWidget *label_host;
GtkWidget *label_pass;
/*This is called in all GTK applications. Arguments are parsed from the command line and are returned to the application.*/
gtk_init (&argc, &argv);
/* create a new window, set its title and put it on center */
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_title (GTK_WINDOW (window), "FTP Client");
gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL);
gtk_container_set_border_width (GTK_CONTAINER (window), 20);
//gtk_window_set_resizable(GTK_WINDOW(window), FALSE); /* window is NOT resizable */
/* Here we construct the container that is going pack our buttons */
grid = gtk_grid_new ();
/* Pack the container in the window */
gtk_container_add (GTK_CONTAINER (window), grid);
/* Add labels */
label_user = gtk_label_new("Username ");
label_host = gtk_label_new("Hostname ");
label_pass = gtk_label_new("Password ");
/* Add hostname entry and label */
h_name = gtk_entry_new();
gtk_grid_attach (GTK_GRID (grid), label_host, 0, 0, 1, 1);
gtk_grid_attach (GTK_GRID (grid), h_name, 1, 0, 1, 1);
/* Add username entry and label */
u_name = gtk_entry_new();
gtk_grid_attach (GTK_GRID (grid), label_user, 0, 1, 1, 1);
gtk_grid_attach (GTK_GRID (grid), u_name, 1, 1, 2, 1);
/* Add password entry and label (visibility set to 0 = not visible */
pass = gtk_entry_new();
gtk_grid_attach (GTK_GRID (grid), label_pass, 0, 2, 1, 1);
gtk_entry_set_visibility (GTK_ENTRY (pass), 0);
gtk_grid_attach (GTK_GRID (grid), pass, 1, 2, 1, 1);
/* Add connect button */
button = gtk_button_new_with_label ("Connect");
g_signal_connect (button, "clicked", G_CALLBACK (print_hello), NULL);
gtk_grid_attach (GTK_GRID (grid), button, 0, 3, 2, 1);
/* Add quit button */
button = gtk_button_new_with_label ("Quit");
g_signal_connect (button, "clicked", G_CALLBACK (gtk_main_quit), NULL);
gtk_grid_attach (GTK_GRID (grid), button, 0, 4, 2, 1);
/* Now that we are done packing our widgets, we show them all in one go, by calling gtk_widget_show_all() on the window.*/
gtk_widget_show_all (window);
/* All GTK applications must have a gtk_main(). Control ends here and waits for an event to occur (like a key press or a mouse event),
* until gtk_main_quit() is called. */
gtk_main ();
return 0;
}
The problem in that code is that I cannot resize widget if window will be resized. I think that is a gtk_grid problem so I cannot understand how to make "widget fit the window".
How can I do?
PS: i prefer to use the gtk_grid because with GTK+3.4 gtk_table has been deprecated
Set the "hexpand" and/or "vexpand" properties to TRUE on the widgets you want to be expanded. For example, add this code and you'll see u_name fill the available space:
gtk_widget_set_hexpand(u_name, TRUE);
gtk_widget_set_vexpand(u_name, TRUE);

Resources