如何在GtkEntry中设置占位符文本

时间:2014-05-05 10:41:44

标签: c gtk gtkentry

我试过这个例子:

#include <stdio.h>
#include <stdlib.h>
#include <gtk/gtk.h>

GdkPixbuf *create_pixbuf(const gchar * filename) {    
    GdkPixbuf *pixbuf;
    GError *error = NULL;
    pixbuf = gdk_pixbuf_new_from_file(filename, &error);

    if(!pixbuf) {       
        fprintf(stderr, "%s\n", error->message);    g_error_free(error);            
    }

    return pixbuf; 
}

void implement() {    
    printf("HI"); 
}    

int main( int argc, char *argv[]) {    
    GtkWidget *window;
    GtkWidget *frame;
    GtkWidget *label;
    GtkWidget *text;    

    gtk_init(&argc, &argv);
    window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    gtk_window_set_title(GTK_WINDOW(window), "New Message");
    gtk_window_set_default_size(GTK_WINDOW(window), 310, 390);
    gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
    gtk_window_set_icon(GTK_WINDOW(window), create_pixbuf("web.png"));

    frame = gtk_fixed_new();
    gtk_container_add(GTK_CONTAINER(window), frame);        

    text = gtk_entry_new();
    gtk_entry_set_max_length (GTK_ENTRY (text), 0);
    gtk_entry_set_width_chars (GTK_ENTRY (text), 37);
    gtk_entry_set_placeholder_text(GTK_ENTRY (text), "Send a message");
    gtk_fixed_put(GTK_FIXED(frame), text, 2, 360);      

    gtk_widget_show_all(window);        

    g_signal_connect(window, "destroy", G_CALLBACK (gtk_main_quit), NULL);

    gtk_main();

    return 0;    
}

但收到错误:undefined reference to gtk_entry_set_placeholder_text'`

1 个答案:

答案 0 :(得分:1)

确保您的GTK +版本为3.2或更高版本,因为在添加该特定功能时就是这样。