-------------------------------------------------------------------------------- --# GTK Entry for getting small amounts of text -------------------------------------------------------------------------------- include GtkEngine.e constant docs = `Type the name of the animal in the entry box below, then click OK ` constant win = create(GtkWindow,"border=10,position=1,$destroy=Quit") constant panel = add(win,create(GtkBox,"orientation=VERTICAL")) constant lbl = add(panel,create(GtkLabel,{{"markup",docs}})) constant fox = create(GdkPixbuf,"thumbnails/fox.png",20,20) constant edt = create(GtkEntry,{ {"margin top",10}, {"margin_bottom",10}, {"icon from pixbuf",1,fox}, {"icon activatable",1,TRUE}, {"icon tooltip markup",1,"Click me to show the entered text"}, {"placeholder text","Name this animal"}}) connect(edt,"activate",_("ShowEntry")) -- on connect(edt,"icon-press",_("ShowEntry")) -- on icon clicked add(panel,edt) constant btn1 = create(GtkButton,"gtk-quit","Quit") set(btn1,"tooltip markup","Press to quit") constant btn2 = create(GtkButton,"gtk-ok",_("ShowEntry")) set(btn2,"tooltip markup","Press to display the entered text") constant btnbox = create(GtkButtonBox,"spacing=5") add(btnbox,{btn1,btn2}) pack(panel,-btnbox) set(btn2,"grab focus") -- workaround for a bug in 'placeholder text' - see GtnEntry GTK docs show_all(win) main() ----------------------------------------------------------- function ShowEntry() ----------------------------------------------------------- object guess = get(edt,"text") if length(guess) = 0 then guess = "nothing" end if if equal(lower(guess),"fox") then Info(win,"Answer","Correct!", sprintf("It is a %s",{guess})) else if Question(win,"Sorry!", sprintf("%s is not correct",{guess}), "Want to try again?") = MB_NO then Quit() end if set(edt,"text","") end if return 1 end function