#include <gtk/gtk.h>
void get_name_click(GtkButton *button,gpointer user_data)
{
guint16 length = 0;
const gchar *name;
length = gtk_entry_get_text_length(user_data);
if(length)
{
name = gtk_entry_get_text(user_data);
g_print("input name is: %s\n", name);
}
else
{
g_print("input empty!\n");
}
}
void search_click(GtkButton *button,gpointer user_data)
{
const gchar *keyword = gtk_entry_get_text(user_data);
g_print("input word is: %s\n", keyword);
}
void cb_text_select(GtkComboBox *widget,gpointer user_data)
{
gchar *value = gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(widget));
g_print("you selected value is: %s\n", value);
}
int main(int argc,char *argv[ ])
{
GtkWidget *window,*fixed;
GtkWidget *entry_name,*label_name,*button_name;
GtkWidget *entry_search,*label_search,*button_search;
GtkWidget *mult_text;
GtkWidget *scale,*spinner;
GtkWidget *label_select,*cb_text;
gtk_init(&argc,&argv);
window=gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(window),"hello fishc - for input");
gtk_widget_set_size_request(GTK_WIDGET(window),300,300);
fixed = gtk_fixed_new();
gtk_container_add(GTK_CONTAINER(window), fixed);
label_name = gtk_label_new("Name: ");
entry_name = gtk_entry_new();
button_name = gtk_button_new_with_label("get name");
g_signal_connect(GTK_WIDGET(button_name), "clicked", G_CALLBACK(get_name_click), entry_name);
gtk_fixed_put(GTK_FIXED(fixed), label_name, 5,22);
gtk_fixed_put(GTK_FIXED(fixed), entry_name, 50,20);
gtk_fixed_put(GTK_FIXED(fixed), button_name, 220,16);
label_search = gtk_label_new("Search: ");
entry_search = gtk_search_entry_new();
button_search = gtk_button_new_with_label("search");
g_signal_connect(GTK_WIDGET(button_search), "clicked", G_CALLBACK(search_click), entry_search);
gtk_entry_set_icon_from_stock(GTK_ENTRY(entry_search), GTK_ENTRY_ICON_SECONDARY, GTK_STOCK_FIND);
gtk_fixed_put(GTK_FIXED(fixed), label_search, 5,52);
gtk_fixed_put(GTK_FIXED(fixed), entry_search, 50,50);
gtk_fixed_put(GTK_FIXED(fixed), button_search, 220,46);
mult_text = gtk_text_view_new();
gtk_widget_set_size_request(GTK_WIDGET(mult_text),290,100);
gtk_fixed_put(GTK_FIXED(fixed), mult_text, 5,80);
scale = gtk_scale_new_with_range(GTK_ORIENTATION_HORIZONTAL, 0,100,1);
gtk_widget_set_size_request(GTK_WIDGET(scale),100,1);
gtk_fixed_put(GTK_FIXED(fixed), scale, 5,180);
spinner = gtk_spin_button_new_with_range(0,10,1);
gtk_fixed_put(GTK_FIXED(fixed), spinner, 125,195);
label_select = gtk_label_new("Please select an item: ");
gtk_fixed_put(GTK_FIXED(fixed), label_select, 5,230);
cb_text = gtk_combo_box_text_new();
gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(cb_text), "aaaaa");
gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(cb_text), "bbb");
gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(cb_text), "cccc");
gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(cb_text), "ffff");
g_signal_connect(GTK_WIDGET(cb_text), "changed", G_CALLBACK(cb_text_select), NULL);
gtk_fixed_put(GTK_FIXED(fixed), cb_text, 150,225);
gtk_widget_show_all(window);
gtk_main();
return 0;
}
其中的GtkScale和GtkSpinButton在按钮部件那一讲说过的,这里就不再赘述。GtkScale和GtkVolumeButton一样的。