Hi, after a long time I was able to find a time to write the blog, because these days I’m very busy with my exam and it will end 29th September. So until that I doubt I’d be able to write much. So sorry for that my all friends who read this.
Related articles..
1) How to create a GUI(Graphical User Interface) using C programming Language..
2) How to create a GUI(Graphical User Interface) using C programming Language.. (part 2)
3) How to create a GUI(Graphical User Interface) using C programming Language.. (part 3)
And this article focus on how to use a Text Entry with button action signals. And the purpose of this program is display the string in the label,which user enter in the text entry.
Contents…
1) Open a Code Blocks projects
2) Open a Glade Project
3) Set properties for the components
4) Code the C Gtk project
5) Run the project
Components
1) Window= mainWindow
2) Label= displayLabel
3) Text Entry= textEntry
4) Button= displayButton
5) Button= exitButton
Set properties
- For the main Window
General–> Name= mainWindow
General–>Resizable= No
Common–>Height request = 400
Common–>Width request=200
- For Display Label
General–>Name=displayLabel
General–>Label=Display
- For Display Button
General–>Name=displayButton
General–>Label=Display
Signals–>Clicked=on_displayButton_clicked
- For Exit Button
General–>Name=exitButton
General–>Label=Exit
Signals–>Clicked=on_exitButton_clicked
- For Text Entry
General–>Name=textEntry
Then save it as TextEntry.glade in libglade format in the CodeBlocks project folder.
In this C project I divided the whole project into three files.
1) main.c
2) callback.c
3) callback.h
The source code of main.c
#include <stdio.h>
#include <gtk/gtk.h>
#include <glade/glade.h>
/*
Author : Gihan De Silva
gihansblog.com
Purpose: This program displays the string in the label,which user enter in the text entry.
*/
GladeXML *xml;
GtkWidget *widget;
int main(int argc, char *argv[])
{
gtk_init(&argc, &argv);
/*import glade file*/
xml = glade_xml_new(“TextEntry.glade”, NULL, NULL);
/* get a widget (useful if you want to change something) */
widget = glade_xml_get_widget(xml, “mainWindow”);
/* connect signal handlers */
glade_xml_signal_autoconnect(xml);
/*show widget*/
gtk_widget_show (widget);
gtk_main();
return 0;
}
The source code of callback.c
#include <stdio.h>
#include <gtk/gtk.h>
#include <glade/glade.h>
GladeXML *xml;
GtkWidget *display;
GtkWidget *textValue;
gchar *d_string;
G_MODULE_EXPORT void on_displayButton_clicked(GtkButton *button,gpointer *data)
{
/* Pull the widgets out of the tree */
display= glade_xml_get_widget(xml, “displayLabel”);
textValue= glade_xml_get_widget(xml, “textEntry”);
/* Get the string value form the Entry widgets */
d_string=gtk_entry_get_text(GTK_ENTRY(textValue));
gtk_label_set_text(GTK_LABEL(display),d_string);
}
G_MODULE_EXPORT void on_exitButton_clicked(GtkButton *button,gpointer *data)
{
gtk_main_quit();
}
The source code of callback.h
G_MODULE_EXPORT void on_displayButton_clicked(GtkButton *button,gpointer *data);
G_MODULE_EXPORT void on_exitButton_clicked(GtkButton *button,gpointer *data);
Now run the gtk project and it will look like this.
And when you hit the Display button, it will display the content in the text entry..
Display Button Code Explained…
Here I’m not going to explain all the code because I already have explained them in previous articles. If you haven’t read previous article, you’d better to read them first. But I’m going to explain the specific things related to this article.
GladeXML *xml;
GtkWidget *display;
GtkWidget *textValue;
gchar *d_string;
G_MODULE_EXPORT void on_displayButton_clicked(GtkButton *button,gpointer *data)
{
/* Pull the widgets out of the tree */
display= glade_xml_get_widget(xml, “displayLabel”);
textValue= glade_xml_get_widget(xml, “textEntry”);
In these two lines, the program will take glade widgets into Gtk widgets.
/* Get the string value form the Entry widgets */
d_string=gtk_entry_get_text(GTK_ENTRY(textValue));
We can’t directly use GtkWidgets to set gtk label, because it needs gchar* type data. So in here we convert to into gchar* .
gtk_label_set_text(GTK_LABEL(display),d_string);
Now with above line we can set it to the label.
}
Ok that’s all for today . If you want, you can DOWNLOAD my CodeBlock project here!. In next post I will show you how to create a simple Calculator using Gtk and Glade.
Thank you
Gihan De Silva
Hello, I need to ask you one thing. Is this site a wordpress weblog? My organization is planning on changing our weblog from Blogger to wordpress, ya think that is practical? In addition did you set up this specific theme by yourself some how? Bless you for your assistance!
Ya I,ve answered the same question earlier, anyway Yes it a wordpress blog and I use Freshy theme 🙂 (http://theme.wordpress.com/themes/freshy/) Only thing I’ve done to the theme is changing the header. If you need any help regarding changing your blog page from Blogger to WordPress read my article on that : https://gihansblog.wordpress.com/2011/06/24/convert-your-blogger-bolg-into-wordpress-or-wordpress-blog-into-blogger/ 😀
I was suggested this web site by my cousin. I am not sure whether this post is written by him as no one else know such detailed about my trouble. You are wonderful! Thanks!
My brother recommended I might like this website. He was entirely right. This post actually made my day. You cann’t imagine just how much time I had spent for this information! Thanks!
You actually make it seem so easy with your presentation but I find this matter to be actually something that I think I would never understand. It seems too complicated and very broad for me. I am looking forward for your next post, I’ll try to get the hang of it!
I have been surfing online more than 3 hours today, yet I never found any interesting article like yours. It is pretty worth enough for me. In my opinion, if all web owners and bloggers made good content as you did, the internet will be a lot more useful than ever before.
I was recommended this web site by my cousin. I’m not sure whether this post is written by him as nobody else know such detailed about my problem. You are incredible! Thanks!
Heya i am for the first time here. I found this board and I find It truly useful & it helped me out a lot. I hope to give something back and help others like you aided me.
Its like you read my mind! You appear to know so much about this, like you wrote the book in it or something. I think that you could do with a few pics to drive the message home a little bit, but instead of that, this is fantastic blog. A fantastic read. I’ll certainly be back.
Hey there, You’ve done a fantastic job. I’ll definitely digg it and personally recommend to my friends. I am sure they’ll be benefited from this web site.
F*ckin’ tremendous issues here. I am very glad to see your post. Thank you a lot and i am having a look ahead to touch you. Will you please drop me a e-mail?
Pretty section of content. I just stumbled upon your blog and in accession capital to assert that I acquire actually enjoyed account your blog posts. Any way I’ll be subscribing to your augment and even I achievement you access consistently quickly.
I loved as much as you’ll receive carried out right here. The sketch is tasteful, your authored material stylish. nonetheless, you command get got an nervousness over that you wish be delivering the following. unwell unquestionably come further formerly again as exactly the same nearly very often inside case you shield this hike.
Thank you for the auspicious writeup. It in fact was a amusement account it. Look advanced to more added agreeable from you! However, how can we communicate?
hello there and thank you for your information – I’ve certainly picked up something new from right here. I did however expertise several technical issues using this web site, since I experienced to reload the web site lots of times previous to I could get it to load properly. I had been wondering if your hosting is OK? Not that I’m complaining, but sluggish loading instances times will very frequently affect your placement in google and can damage your high-quality score if advertising and marketing with Adwords. Well I’m adding this RSS to my e-mail and could look out for much more of your respective fascinating content. Ensure that you update this again soon..
Wonderful page along with very easy for you to figure out justification. Exactly how can My spouse and i attempt receiving concur for you to submit element in the document inside my future news letter? Getting suitable credit history to you personally your journalist along with backlink on the blog won’t certainly be a trouble.
Excellent blog here! Also your web site loads up fast! What web host are you using? Can I get your affiliate link to your host? I wish my web site loaded up as quickly as yours lol
Excuse, I can help nothing. But it is assured, that you will find the correct decision. Do not despair.
Do you mind if I post your article on my Information Blog? I would think this article suits my topic perfectly. Uhmmm, thanks for posting this.
We’re a group of volunteers and opening a new scheme in our community. Your website offered us with valuable information to work on. You’ve done a formidable job and our entire community will be grateful to you.
This is very interesting, You are a very skilled blogger. I have joined your feed and look forward to seeking more of your wonderful post. Also, I’ve shared your site in my social networks!
Excellent post. I was checking constantly this blog and I’m impressed! Very helpful information particularly the last part 🙂 I care for such information much. I was seeking this particular info for a very long time. Thank you and best of luck.
Wonderful goods from you, man. I’ve understand your stuff previous to and you’re just extremely fantastic. I actually like what you’ve acquired here, certainly like what you’re saying and the way in which you say it. You make it enjoyable and you still take care of to keep it sensible. I can’t wait to read far more from you. This is really a tremendous website.
Definitely believe that which you stated. Your favorite justification appeared to be on the net the easiest thing to be aware of. I say to you, I certainly get annoyed while people consider worries that they just don’t know about. You managed to hit the nail upon the top and also defined out the whole thing without having side effect , people could take a signal. Will likely be back to get more. Thanks
I do consider all the ideas you have introduced in your post. They’re really convincing and can definitely work. Still, the posts are very brief for newbies. May just you please lengthen them a bit from next time? Thank you for the post.
Hi, I think that I saw you visited my website so I came to “return the favor�.I am trying to find things to improve my website!I suppose its ok to use some of your ideas!!
You are my role models. Thanks for the article
I love your wordpress web template, exactly where did you download it through?
Wow, incredible blog layout! How long have you been blogging for? you made blogging look easy. The overall look of your web site is fantastic, as well as the content!
Thanks, I’ve recently been seeking for info about this subject for ages and yours is the best I have located so far.
Pretty nice post. I just stumbled upon your blog and wanted to say that I’ve truly enjoyed browsing your blog posts. After all I’ll be subscribing to your feed and I hope you write again very soon!
I loved as much as you’ll receive carried out right here. The sketch is tasteful, your authored subject matter stylish. nonetheless, you command get bought an edginess over that you wish be delivering the following. unwell unquestionably come more formerly again since exactly the same nearly very often inside case you shield this hike.
I really wish I hadn’t noticed this as I genuinely appreciate now!
It’s your pity you actually don’t have got a contribute link! I’d most definitely contribute to that remarkable blog site! I actually presume in the meantime i’ll happy with book-marking plus putting a person’s Rss so that you can this Bing akun. I actually glance forwards so that you can fresh improvements but will publish the following blog site by using this Twitter crew:
As shortly as we rescued this site we went upon reddit to share a small of a adore with them. “Love a small traffic that thou hast learned, as well as be calm therewith.” by Marcus Aurelius Antoninus.
Thank you, I’ve recently been hunting for information about this subject for ages and yours is the best I have found so far.
As soon as I found this internet site I went on reddit to share some of the love with them. “A sect or party is an elegant incognito devised to save a man from the vexation of thinking.” by Ralph Waldo Emerson.
I loved as much as you will receive carried out right here. The sketch is attractive, your authored subject matter stylish. nonetheless, you command get bought an nervousness over that you wish be delivering the following. unwell unquestionably come further formerly again as exactly the same nearly very often inside case you shield this increase.
It’s a pity you don’t have a donate button! I’d certainly donate to this outstanding blog! I suppose for now i’ll settle for book-marking and adding your RSS feed to my Google account. I look forward to brand new updates and will talk about this site with my Facebook group. Talk soon!
I was looking at some of your blog posts on this site and I conceive this site is rattling informative! Keep posting.
I dugg some of you post as I cogitated they were very useful handy
2011…
Excellent website. A lot of useful info here. I am sending it to several friends ans also sharing in delicious. And certainly, thanks for your effort!…
Awesome blog! Is your theme custom made or did you download it from somewhere? A theme like yours with a few simple adjustements would really make my blog shine. Please let me know where you got your design. Thank you
Excellent piece of writing and easy to fully understand story. How do I go about getting agreement to post component of the page in my upcoming newsletter? Offering proper credit to you the source and weblink to the site will not be a problem.
Valuable information. Fortunate me I found your site accidentally, and I am shocked why this twist of fate did not happened earlier! I bookmarked it.
I,need source code
thanks my dear brother i am first semester in IT field so i am very satisfied see your website i read simple c.