cancel
Showing results for 
Search instead for 
Did you mean: 

GTK application does not show the image

TArre.1
Associate III

Hi!

I am using STM32MP157C-DK2 board to create an application on the screen (using GTK library). My idea is to create a window with the following image inside:

0693W00000Y8tpkQAB.pngCreated code:

#include <gtk/gtk.h>
 
int main(int argc, char **argv)
{
    GtkWidget *window;
    GtkWidget *layout;
    GtkWidget *image;
    GtkWidget *button;
 
    gtk_init(&argc, &argv);
 
    window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    gtk_window_set_default_size (GTK_WINDOW (window), 800, 480);
    gtk_window_set_title (GTK_WINDOW (window), "Info window");
    // gtk_window_fullscreen(GTK_WINDOW(window));
    gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
 
    layout = gtk_layout_new(NULL, NULL);
    gtk_container_add(GTK_CONTAINER (window), layout);
    gtk_widget_show(layout);
 
    image = gtk_image_new_from_file("linux.png");
    gtk_layout_put(GTK_LAYOUT(layout), image, 600, 50);
 
    button = gtk_button_new_with_label("PREVIOUS");
    gtk_layout_put(GTK_LAYOUT(layout), button, 150, 300);
    gtk_widget_set_size_request(button, 200, 50);
    g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(gtk_window_close), window);
 
    button = gtk_button_new_with_label("NEXT");
    gtk_layout_put(GTK_LAYOUT(layout), button, 450, 300);
    gtk_widget_set_size_request(button, 200, 50);
    g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(gtk_window_close), window);
 
    gtk_widget_show_all(window);
 
    gtk_main();
 
    return 0;
}

Then I have created executable using STM32CubeIDE and uploaded it with the image file (.png) in the following location:

  • /usr/local

Finally, I have run the GTK application with the following command:

Board $> su -l weston -c "/usr/local/custom_GTK"

Obtained result:0693W00000Y8tseQAB.pngDoes anyone know how I can display the image?

Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
Erwan SZYMANSKI
ST Employee

Hello @TArre.1​,

This kind of problem with GTK really let me think about a wrong path of your image. Try to mention the absolute path of the image (e.g. /usr/local/myimages/linux.png), or be careful to respect the right relative path of it.

Kind regards,

Erwan

In order to give better visibility on the answered topics, please click on 'Select as Best' on the reply which solved your issue or answered your question. See also 'Best Answers'

In order to give better visibility on the answered topics, please click on 'Accept as Solution' on the reply which solved your issue or answered your question.

View solution in original post

2 REPLIES 2
Erwan SZYMANSKI
ST Employee

Hello @TArre.1​,

This kind of problem with GTK really let me think about a wrong path of your image. Try to mention the absolute path of the image (e.g. /usr/local/myimages/linux.png), or be careful to respect the right relative path of it.

Kind regards,

Erwan

In order to give better visibility on the answered topics, please click on 'Select as Best' on the reply which solved your issue or answered your question. See also 'Best Answers'

In order to give better visibility on the answered topics, please click on 'Accept as Solution' on the reply which solved your issue or answered your question.
TArre.1
Associate III

Thank you @Erwan SZYMANSKI​ , with absolute path is working! :beaming_face_with_smiling_eyes: