Thread: GTK+: calculator

  1. #1
    Registered User
    Join Date
    Apr 2005

    GTK+: calculator

    i am developing a calculator in C using GTK+, this code activates when 3 is pressed i was wondering if it is possible to make it generic for all of my number buttons. So as the line gchar str2[] = "3"; could read whatever button was pressed in stead of just "3". I have a feeling it has something to do with accessing the label using info from the following line, could some please help me out
     BTN_3 = gtk_button_new_with_mnemonic (_("3"));
    on_BTN_3_clicked                       (GtkButton       *button,
                                            gpointer         user_data)
    	GtkWidget *resultfld;
    	gchar str2[] = "3";
    	resultfld = GTK_ENTRY(lookup_widge(button, "entry1"));
    	strcat(str, str2);
    	gtk_entry_set_text(resultfld, str);

  2. #2
    SleepWalker tjohnsson's Avatar
    Join Date
    Apr 2004
    Create one callback function, connect that to the every numeric button,
    while installing callback func to the button, use last parameter for passing
    string, integer or whatever you want to the callback function. (user_data). can also set any data (gpointer) to the button using g_object_set_data, and get it whenever you need it.
    or maybe you wanna read label from button to get button numeric string representation.
    And again replace that strcat ...
    -- Add Your Signature Here --

  3. #3
    Registered User
    Join Date
    Apr 2005
    thanks that helped me out alot

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. GUI Calculator - Critique
    By The Brain in forum Windows Programming
    Replies: 1
    Last Post: 02-25-2006, 04:39 AM
  2. Calculator + LinkedList
    By maro009 in forum C++ Programming
    Replies: 20
    Last Post: 05-17-2005, 12:56 PM
  3. Need help with calculator program
    By Kate in forum C# Programming
    Replies: 1
    Last Post: 01-16-2004, 10:48 AM
  4. Java Calculator
    By datainjector in forum A Brief History of
    Replies: 7
    Last Post: 11-12-2002, 08:39 PM
  5. Replies: 2
    Last Post: 05-10-2002, 04:16 PM