|
楼主 |
发表于 2004-8-17 17:26:52
|
显示全部楼层
是放在回调函数中insert吗?
我运行了但是不能加进去,能帮我看看程序吗?
#include <locale.h>
#include <gtk/gtk.h>
void enter_callback(GtkWidget *widget, GtkWidget *entry,GtkWidget *text, gchar *addtext)
{
gchar *entry_text;
entry_text = gtk_entry_get_text(GTK_ENTRY(entry));
gtk_text_insert(GTK_TEXT (text), NULL, NULL, NULL,"Supports ", -1);
printf("Entry contents: %s\n", entry_text);
}
int main (int argc, char *argv[])
{
GtkWidget *window;
GtkWidget *vbox, *hbox, *box1;
GtkWidget *entry;
GtkWidget *button;
GtkWidget *check;
GtkWidget *clist;
GtkWidget *text;
GtkWidget *vscrollbar;
GtkWidget *table;
gchar *titles[1] = {"NAME"};
gchar *name[1]={"tom"};
gchar *addtext="123";
gtk_set_locale();
gtk_rc_add_default_file("./gtkrc.zh");
gtk_init (&argc, &argv);
/* create a new window */
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_widget_set_usize( GTK_WIDGET (window), 500, 500);
gtk_window_set_title(GTK_WINDOW (window), "GTK Entry");
gtk_signal_connect(GTK_OBJECT (window), "delete_event",
(GtkSignalFunc) gtk_exit, NULL);
vbox = gtk_vbox_new (FALSE, 0);
gtk_container_add (GTK_CONTAINER (window), vbox);
gtk_widget_show (vbox);
hbox = gtk_hbox_new (FALSE, 0);
gtk_container_add (GTK_CONTAINER (vbox), hbox);
gtk_widget_show (hbox);
table = gtk_table_new (2, 2, FALSE);
gtk_table_set_row_spacing (GTK_TABLE (table), 0, 2);
gtk_table_set_col_spacing (GTK_TABLE (table), 0, 2);
gtk_box_pack_start (GTK_BOX (hbox), table, TRUE, TRUE, 0);
gtk_widget_show (table);
/*鍒涘缓G t k T e x t鏋勪欢 */
text = gtk_text_new (NULL, NULL);
gtk_text_set_editable (GTK_TEXT (text), TRUE);
gtk_text_set_word_wrap (GTK_TEXT (text), FALSE);
gtk_table_attach (GTK_TABLE (table), text, 0, 1, 0, 1,
GTK_EXPAND | GTK_SHRINK | GTK_FILL,
GTK_EXPAND | GTK_SHRINK | GTK_FILL, 0, 0);
gtk_widget_show (text);
/*缁橤 t k T e x t鏋勪欢娣诲姞鍨傜洿婊氬姩鏉?*/
vscrollbar = gtk_vscrollbar_new (GTK_TEXT (text)->vadj);
gtk_table_attach (GTK_TABLE (table), vscrollbar, 1, 2, 0, 1,
GTK_FILL, GTK_EXPAND | GTK_SHRINK | GTK_FILL, 0, 0);
gtk_widget_show (vscrollbar);
/* 瀹炵幇鏂囨湰鏋勪欢 鍙?互鎻掑叆涓 |
|