GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Sun Nov 23, 2014 12:06 pm

All times are UTC




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Add another button
PostPosted: Sun Mar 02, 2014 5:04 pm 
Offline

Joined: Sat Mar 01, 2014 12:17 pm
Posts: 4
Hello, this is my first attempt at making a GTK GUI with C
I managed to create one button with a picture as I wanted, but now stuck with figuring out how to add more buttons just like that, and if possible to even make the buttons transparent.

Code...
Code:
   hbox = gtk_hbox_new(FALSE, 6);
//button actions
   button = gtk_button_new();
   g_signal_connect(button, "clicked", G_CALLBACK(gtk_main_quit), NULL);
   gtk_container_add(GTK_CONTAINER(window), button);

   image = gtk_image_new_from_file(file1);
   image2 = gtk_image_new_from_file(file2);
   //label = gtk_label_new("kkk");

   gtk_box_pack_start(GTK_BOX(hbox), image, FALSE, TRUE, 0);
   //gtk_box_pack_start(GTK_BOX(hbox), label, TRUE, TRUE, 0);

//2

   gtk_container_add(GTK_CONTAINER(button), hbox);

   gtk_widget_show_all(window);

   gtk_main();
   return 0;
}


Top
 Profile  
 
 Post subject: Re: Add another button
PostPosted: Wed Mar 05, 2014 5:43 pm 
Offline

Joined: Sat Mar 01, 2014 12:17 pm
Posts: 4
I also wanted to specify that I'm using gtk3.
The button is created successfully, however all attempts to adding more buttons went bad.
Either two icons went into one button or the two icons and no buttons.
Just couldn't figure out how to go on..

Thank you


Top
 Profile  
 
 Post subject: Re: Add another button
PostPosted: Thu Mar 06, 2014 5:38 am 
Offline
GTK+ Guru

Joined: Fri Mar 25, 2011 5:16 pm
Posts: 177
Location: USA
Have a look at my tutorial here: http://www.gtkforums.com/viewtopic.php?f=3&t=988&p=196067=SIGNALS+II#p196067

Also:
1) Don't use hbox it's been deprecated as of Gtk 3.2, use GtkGrid instead. It says to use GtkBox but it's eventually going away also, this isn't mentioned in the documentation for GtkBox. It only tells you that in the documentation for GtkHBox and GtkVbox and even then only in GTK versions 3.2 and above.
Quote:
gtk_hbox_new has been deprecated since version 3.2 and should not be used in newly-written code. You can use gtk_box_new() with GTK_ORIENTATION_HORIZONTAL instead, wich is a very quick and easy change. But the recommendation is to switch to GtkGrid, since GtkBox is going to go away eventually. See Migrating from other containers to GtkGrid.

http://developer.gnome.org/gtk3/3.2/GtkHBox.html#gtk-hbox-new
Migrating from other containers to GtkGrid
https://developer.gnome.org/gtk3/stable/gtk-migrating-GtkGrid.html

2) Change gtk_image_new_from_stock in my code to gtk_image_new_from_file


Top
 Profile  
 
 Post subject: Re: Add another button
PostPosted: Thu Mar 06, 2014 6:09 pm 
Offline

Joined: Sat Mar 01, 2014 12:17 pm
Posts: 4
Looks awesome, definitely will check it out :)


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

All times are UTC


Who is online

Users browsing this forum: HeadAche, Yahoo [Bot] 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:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group