GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Thu Nov 26, 2015 12:25 pm

All times are UTC

Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: problem with Text entries...
PostPosted: Thu Mar 01, 2007 10:28 am 

Joined: Thu Mar 01, 2007 9:58 am
Posts: 1
I'm new to GTK and started programming in C language.
While doing with text entries, I'm getting problem. My problem is..
How to add two numbers when each number is taken from the entry boxes and display the answer there itself in the Window when the add button is pressed...... [Just like Calculator]..Please Help me..


 Post subject:
PostPosted: Thu Mar 01, 2007 8:09 pm 
Never Seen the Sunlight

Joined: Wed Sep 21, 2005 12:07 am
Posts: 563
Location: Portland, OR USA
Well, there are lots of ways to do it. For example, you callback function can have a static variable to hold the previous value and use the g_strtod to convert the value in the entry into a numeric.

simple example... not tested, just off the top of my head:

  gdouble previous_value;
  gdouble value;
  gchar new_text;

  value = g_strtod (gtk_entry_get_text ( GTK_ENTRY (widget) );
  if (previous_value)
    value += previous_value;
    previous_value = null;
    new_text = g_strdup_printf ("%f", value);
    gtk_entry_set_text (GTK_ENTRY (widget), new_text);
    /* don't free new_text, it's owned by the entry */
    previous_value = value;

Micah Carrick - Forum Administrator

Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC

Who is online

Users browsing this forum: Yahoo [Bot] and 2 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