cgtkgtkentry

How to get the value of an entry in GTK+


I have a problem I need help with. I'm making a C program that will be able to encrypt and decrypt using either DES or RSA. For making a GUI mostly because the lack of a better option, I went with GTK, but I need some guidance on how to store text from an entry on pressing a button.

So if the user types in something to a given entry field and presses "Encrypt", I need to store what he wrote in somehow, as I need to make the actual encryption, but couldn't find a suitable command for this. The only thing I could do was to get it written to the console which is not really helpful, plus I need to get the actual encrypted message back to another Entry.


Solution

  • Easy, I understand that you know how to catch clicked signal for your button, in your callback:
    1.- Grab the user input with gtk_label_get_text. Since the function returns a const string, you need to make a copy of it with functions like g_strdup or save it in another buffer to process the encryption.
    2.- Encrypt the string.
    3.- Send back the encrypted string with gtk_label_set_text