当我点击send_button_clicked()时;我想获取条目“entryform1”中的值,我该怎么做?我的代码如下:
gtkwidgete1 = GTK_ENTRY( gtk_builder_get_object( gtkBuilder, "chave_Sessao_TextBox" ) );
const gchar *text1 = gtk_entry_get_text(e1);strcpy(ch1,text1);
g_print ("Contents of entries:%s\n", text1);
最佳答案
来自GNOME's GTK+ 2.0 Documentation :
The contents of the Entry can be retrieved by using a call to the following function. This is useful in the callback functions described below:
const gchar *gtk_entry_get_text(GtkEntry *entry);
就这么简单。因此,请执行以下操作:
GtkWidget *e1 = gtk_entry_new();
/* Set up whatever else you want to with your entry here */
g_signal_connect(e1, "activate", G_CALLBACK(print_message, e1));
gtk_box_pack_start (GTK_BOX (yourgtkbox), e1, TRUE, TRUE, 0);
gtk_widget_show(e1);
并在回调函数中print_message
打印出消息:
const gchar *text1 = gtk_entry_get_text(GTK_ENTRY (e1));
g_print ("Entry contents: %s\n", text1);
在 GTK 中,gchar
只是 char
的 typedef
,因此您无需将其复制到另一个字符串中。
有关更多示例,请参阅提供的链接。
关于c - 如何获取输入文本GTK2 + Glade的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44782817/