如何获取输入文本的值 GTK2 + Glade
How to get the values of input text GTK2 + Glade
当我点击 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
只是 typedef
到 char
,因此您无需将其复制到另一个字符串中。
有关更多示例,请参阅提供的 link。
当我点击 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
只是 typedef
到 char
,因此您无需将其复制到另一个字符串中。
有关更多示例,请参阅提供的 link。