Re: gtk_widget_show() not showing window



Try this instead.  The gtk_widget_show_all() then gtk_widget_hide() then
gtk_widget_show() is the cause of your problem; unless you were thinking
the window should blink once before appearing.

James,

    #include <gtk/gtk.h>


    static void
    button_clicked_cb(GtkButton *button, gpointer data)
    {
      GtkWidget *window2;
      window2 = gtk_window_new(GTK_WINDOW_TOPLEVEL);
      gtk_widget_show_all(window2);
    }

    int
    main(int argc, char **argv)
    {
      GtkWidget *window;
      GtkWidget *button;

      gtk_init(&argc, &argv);

      window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
      g_signal_connect(G_OBJECT(window), "delete_event",
                       G_CALLBACK(gtk_main_quit), NULL);

      button = gtk_button_new_with_label("Click me");
      g_signal_connect(G_OBJECT(button), "clicked",
                       G_CALLBACK(button_clicked_cb), NULL);
      gtk_container_add(GTK_CONTAINER(window), button);

      gtk_widget_show_all(window);
      gtk_main();

      return 0;
    }


On Mon, 2007-08-27 at 19:00 +0000, G. Paul Ziemba wrote:

Greetings,

gtk_widget_show() does not seem to be operating the way I expect;
could one of the experts please tell me if something is wrong with
this code or if something is wrong with gtk?

When I run this small bit of code, the window appears briefly
and then disappears immediately. The program does not exit.
I expect the window to stay visible (due to gtk_widget_show()),
but it's not happening.

many thanks!

Versions:
    OS: FreeBSD 6.2-STABLE #0: Sun Jun  3 19:55:09 PDT 2007
    gtk: gtk-2.10.12, gtk-2.10.14


Test program compiled with:
    gcc -o test test.c `pkg-config --cflags --libs gtk+-2.0`

Test Program:
    #include <gtk/gtk.h>

    static void
    button_clicked_cb(GtkButton *button, gpointer data)
    {
      GtkWidget *window2;
      window2 = gtk_window_new(GTK_WINDOW_TOPLEVEL);
      gtk_widget_show_all(window2);
      gtk_widget_hide(window2);
      gtk_widget_show(window2);
    }

    int
    main(int argc, char **argv)
    {
      GtkWidget *window;
      GtkWidget *button;

      gtk_init(&argc, &argv);

      window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
      g_signal_connect(G_OBJECT(window), "delete_event",
                       G_CALLBACK(gtk_main_quit), NULL);

      button = gtk_button_new_with_label("Click me");
      g_signal_connect(G_OBJECT(button), "clicked",
                       G_CALLBACK(button_clicked_cb), NULL);
      gtk_container_add(GTK_CONTAINER(window), button);

      gtk_widget_show_all(window);
      gtk_widget_hide(window);
      gtk_widget_show(window);

      gtk_main();

      return 0;
    }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]