GTK+ Forums Forum Index GTK+ Forums
Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

problem with Text entries...

 
Post new topic   Reply to topic    GTK+ Forums Forum Index -> GTK+ Programming
Author Message
hari



Joined: 01 Mar 2007
Posts: 1

PostPosted: Thu Mar 01, 2007 10:28 am    Post subject: problem with Text entries... Reply with quote

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..
Back to top
Micah Carrick
Never Seen the Sunlight


Joined: 21 Sep 2005
Posts: 407
Location: Portland, OR USA

PostPosted: Thu Mar 01, 2007 8:09 pm    Post subject: Reply with quote

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:

Code: (Plaintext)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
  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 */
  }
  else
  {
    previous_value = value;
  }
Back to top
Display posts from previous:   
Post new topic   Reply to topic    GTK+ Forums Forum Index -> GTK+ Programming All times are GMT
Page 1 of 1

 


Powered by phpBB © 2001, 2005 phpBB Group
CodeBB 1.0 Beta 2
Protected by Anti-Spam ACP