
This an entry widget. An entry widget is a container that you can type in to.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
#!/usr/bin/gjs
Gtk = imports.gi.Gtk;
Gtk.init(null, 0);
myW = new Gtk.Window({type: Gtk.WindowType.TOPLEVEL});
myW.title = "Entry";
myW.connect("destroy", function(){Gtk.main_quit()});
grid = new Gtk.Grid();
myW.add(grid);
//create the entry widget
var entry = new Gtk.Entry();
entry.set_placeholder_text("Write something here");
entry.set_width_chars(50);
//create the first label
var label = new Gtk.Label({label: "Entry widget: "});
//create the button for connecting
var connectionbutton = new Gtk.Button({label: "Click to update label"});
//create the label for updating the entrys information
this.resultlabel = new Gtk.Label({
label: "Entry contents go here after the click"
});
//create a connection between the button and the result label
connectionbutton.connect("clicked", function(widget, event) {
//getting the text from the entry widget and updating the label
var whatWasTyped = entry.get_text();
this.resultlabel.set_text(whatWasTyped);
});
grid.attach(label, 1, 1, 1, 1);
grid.attach_next_to(entry,label,1,1,1);
grid.attach_next_to(connectionbutton,label,3,1,1);
grid.attach_next_to(resultlabel,entry,3,1,1);myW.show_all();
Gtk.main();
In this sample we use the following widgets: Gtk.Window, Gtk.Grid, Gtk.Entry, Gtk.Label, Gtk.Button.
Got a comment? Spotted an error? Found the instructions unclear? Send feedback about this page.