GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Sat Dec 20, 2014 3:51 pm

All times are UTC




Post new topic Reply to topic  [ 11 posts ] 
Author Message
 Post subject: I'm just tryin to setup menu for GTK+ but it is not working
PostPosted: Sun Jan 12, 2014 5:05 pm 
Offline
Familiar Face

Joined: Fri Jan 10, 2014 2:29 pm
Posts: 21
I'm just tryin to setup menu for GTK+ , I'm using GTK 3.0 here is my code but it only shows Window with title "title"
Code:
#include <stdio.h>
#include <gtk/gtk.h>

int main(int argc,char *argv[]){
   GtkWidget *vbox;
   GtkWidget *window;

   GtkWidget *menu;
   GtkWidget *filemenu;
   GtkWidget *file;
   GtkWidget *quit;

   gtk_init(&argc,&argv);

   window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    gtk_window_set_title(GTK_WINDOW(window),"title");
    gtk_widget_show(window);

   vbox = gtk_vbox_new(FALSE,0);
   gtk_container_add(GTK_CONTAINER(window),vbox);

   menu = gtk_menu_bar_new();

   filemenu = gtk_menu_new();

   file = gtk_menu_item_new_with_label("file");
   quit = gtk_menu_item_new_with_label("quit");

   gtk_menu_item_set_submenu(GTK_MENU_ITEM(file),filemenu);
   gtk_menu_shell_append(GTK_MENU_SHELL(filemenu),quit);
   gtk_menu_shell_append(GTK_MENU_SHELL(filemenu),file);
   gtk_box_pack_start(GTK_BOX(vbox),menu,FALSE,FALSE,3);

   gtk_widget_show_all(window);

   g_signal_connect(window,"destroy",G_CALLBACK(gtk_main_quit),NULL);

    g_signal_connect(quit, "activate",G_CALLBACK(gtk_main_quit), NULL);


    gtk_main();


return 0;



}


Top
 Profile  
 
 Post subject: Re: I'm just tryin to setup menu for GTK+ but it is not work
PostPosted: Mon Jan 13, 2014 7:29 am 
Offline
Never Seen the Sunlight

Joined: Mon Apr 28, 2008 5:52 am
Posts: 799
Location: UK
Hello,

Below is the corrected code and slightly tidied up. What you had done was place all menu items in a menu and none in the menu bar it self. Therefore there was nothing to show.

Code:
#include <gtk/gtk.h>

int main(int argc,char *argv[])
{
   GtkWidget *vbox;
   GtkWidget *window;

   GtkWidget *menu;
   GtkWidget *filemenu;
   GtkWidget *file;
   GtkWidget *quit;

   gtk_init(&argc,&argv);

   window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
   gtk_window_set_title(GTK_WINDOW(window), "title");

   vbox = gtk_vbox_new(FALSE, 0);
   gtk_container_add(GTK_CONTAINER(window), vbox);

   menu = gtk_menu_bar_new();

   filemenu = gtk_menu_new();

   file = gtk_menu_item_new_with_label("File");
   quit = gtk_menu_item_new_with_label("Quit");

   gtk_menu_item_set_submenu(GTK_MENU_ITEM(file), filemenu);
   gtk_menu_shell_append(GTK_MENU_SHELL(filemenu), quit);
   gtk_menu_shell_append(GTK_MENU_SHELL(menu), file); /* Error was here */
   gtk_box_pack_start(GTK_BOX(vbox), menu, FALSE, FALSE, 3);

   gtk_widget_show_all(window);

   g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);

   g_signal_connect(quit, "activate", G_CALLBACK(gtk_main_quit), NULL);

   gtk_main();

   return 0;
}

_________________
E.


Top
 Profile  
 
 Post subject: Re: I'm just tryin to setup menu for GTK+ but it is not work
PostPosted: Mon Jan 13, 2014 8:57 am 
Offline
Familiar Face

Joined: Fri Jan 10, 2014 2:29 pm
Posts: 21
Errol Fella I just executed your code ! but it is not working fine ! again it is showing just blank window with title "title" i'm giving a screen shot of my screen and the final code which i have executed Here is the Code which i have executed http://www.codejaw.com/v5ypp


Attachments:
File comment: this is screen shot of executed programme
screen.png
screen.png [ 155.1 KiB | Viewed 466 times ]
Top
 Profile  
 
 Post subject: Re: I'm just tryin to setup menu for GTK+ but it is not work
PostPosted: Tue Jan 14, 2014 5:30 pm 
Offline
GTK+ Guru

Joined: Fri Mar 25, 2011 5:16 pm
Posts: 180
Location: USA
Your error message is telling you that GtkVBox isn't used anymore and to use GtkBox instead. But the preferred way is to GtkGrid because GtkBox is going away eventually. See here:

http://www.gtkforums.com/viewtopic.php?f=3&t=988&p=195349=Gtk3+with+CSS%3A+GtkCalendar#p195349

I also highly recommend installing Devhelp as I've mentioned in the "Reference Manuals" section of the tutorials. This will ensure your looking at the documentation for your exact version of GTK.

http://www.gtkforums.com/viewtopic.php?f=3&t=988&p=2357=This+page+is+a+collection+of+information#p2357


Top
 Profile  
 
 Post subject: Re: I'm just tryin to setup menu for GTK+ but it is not work
PostPosted: Tue Jan 14, 2014 6:03 pm 
Offline
Familiar Face

Joined: Fri Jan 10, 2014 2:29 pm
Posts: 21
ZeroHour , I've already tried this but output is still the same ! only difference is that there is no warning in console . :(


Top
 Profile  
 
 Post subject: Re: I'm just tryin to setup menu for GTK+ but it is not work
PostPosted: Tue Jan 14, 2014 6:30 pm 
Offline
Never Seen the Sunlight

Joined: Mon Apr 28, 2008 5:52 am
Posts: 799
Location: UK
This is the code again but using GtkGrid. This compiles well on my machine and displays the menu as expected without showing the run-time error message.

Code:
#include <gtk/gtk.h>

int main(int argc,char *argv[])
{
   GtkWidget *grid;
   GtkWidget *window;

   GtkWidget *menu;
   GtkWidget *filemenu;
   GtkWidget *file;
   GtkWidget *quit;

   gtk_init(&argc,&argv);

   window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
   gtk_window_set_title(GTK_WINDOW(window), "title");

   grid = gtk_grid_new();
   gtk_container_add(GTK_CONTAINER(window), grid);

   menu = gtk_menu_bar_new();
   filemenu = gtk_menu_new();

   file = gtk_menu_item_new_with_label("File");
   quit = gtk_menu_item_new_with_label("Quit");

   gtk_menu_item_set_submenu(GTK_MENU_ITEM(file), filemenu);
   gtk_menu_shell_append(GTK_MENU_SHELL(filemenu), quit);
   gtk_menu_shell_append(GTK_MENU_SHELL(menu), file); /* Error was here */

   gtk_grid_attach(GTK_GRID(grid), menu, 0, 0, 1, 1);

   g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);
   g_signal_connect(quit, "activate", G_CALLBACK(gtk_main_quit), NULL);

   gtk_widget_show_all(window);

   gtk_main();

   return 0;
}

_________________
E.


Top
 Profile  
 
 Post subject: Re: I'm just tryin to setup menu for GTK+ but it is not work
PostPosted: Wed Jan 15, 2014 5:57 am 
Offline
Familiar Face

Joined: Fri Jan 10, 2014 2:29 pm
Posts: 21
Then i guess i have something wrong with my installed version of GTK cause it still shows a blank screen for me with just "title", maybe i should reinstall , anyway thanks for your time Fellas i'll figure it out


Top
 Profile  
 
 Post subject: Re: I'm just tryin to setup menu for GTK+ but it is not work
PostPosted: Wed Jan 15, 2014 6:38 am 
Offline
Never Seen the Sunlight

Joined: Mon Apr 28, 2008 5:52 am
Posts: 799
Location: UK
Are you using the Unity Desktop? If you are then what may have happened is that it has stripped out the menu bar from the window and placed it at the top left of the screen. I only just spotted the word "Title" on your screen shot in the top left.

_________________
E.


Top
 Profile  
 
 Post subject: Re: I'm just tryin to setup menu for GTK+ but it is not work
PostPosted: Wed Jan 15, 2014 12:15 pm 
Offline
Familiar Face

Joined: Fri Jan 10, 2014 2:29 pm
Posts: 21
Yeah , i mean yes i'm using UBUNTU and it uses unity ! so your assumption might be correct so what should i do ?


Top
 Profile  
 
 Post subject: Re: I'm just tryin to setup menu for GTK+ but it is not work
PostPosted: Wed Jan 15, 2014 1:03 pm 
Offline
Never Seen the Sunlight

Joined: Mon Apr 28, 2008 5:52 am
Posts: 799
Location: UK
Your menu is now in the top left of your screen. This is a "feature" of the Unity desktop called the Global Menu Bar. I notice it has also done the same to the terminal window as that does not have a menu bar inside it.

There are ways around this. First you could stop using the Unity desktop. Another way is to follow the tips at this link http://lifehacker.com/5887462/how-to-disable-ubuntus-annoying-global-menu-bar

_________________
E.


Top
 Profile  
 
 Post subject: Re: I'm just tryin to setup menu for GTK+ but it is not work
PostPosted: Wed Jan 15, 2014 2:24 pm 
Offline
Familiar Face

Joined: Fri Jan 10, 2014 2:29 pm
Posts: 21
You were Right ! yeah it works you code is working fine well unity's got some bad features even though good for UI point of view , but still menu part is quite sick ! THNAKS A LOT GUYZ [PROBLEM SOLVED] MENU IS WORKING


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 11 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group