#!/usr/bin/env python # example entry.py import gtk class EntryExample: def enter_callback(self, widget, label): entry_text = widget.get_text() print "Entry %s contents: %s\n" % (label.get_text(),entry_text) def entry_toggle_editable(self, checkbutton, entry): entry.set_editable(checkbutton.get_active()) def entry_toggle_visibility(self, checkbutton, entry): entry.set_visibility(checkbutton.get_active()) def __init__(self): # create a new window window = gtk.Window(gtk.WINDOW_TOPLEVEL) window.set_size_request(200, 100) window.set_title("Label and Entry") window.connect("delete_event", gtk.mainquit) vbox = gtk.VBox(gtk.FALSE, 0) window.add(vbox) vbox.show() table = gtk.Table(2,2) vbox.pack_start(table, gtk.TRUE, gtk.TRUE, 0) label = gtk.Label("Login ID") label.set_alignment(1,0.5) table.attach(label,0,1,0,1,xpadding=10) label.show() entry = gtk.Entry() entry.set_max_length(50) entry.connect("activate", self.enter_callback, label) entry.set_text("hello") entry.insert_text(" world", len(entry.get_text())) entry.select_region(0, len(entry.get_text())) table.attach(entry,1,2,0,1,xpadding=10) entry.show() label = gtk.Label("Key words") label.set_alignment(1,0.5) table.attach(label,0,1,1,2,xpadding=10) label.show() entry = gtk.Entry() entry.set_max_length(50) entry.connect("activate", self.enter_callback, label) table.attach(entry,1,2,1,2,xpadding=10) entry.show() table.show() hbox = gtk.HBox(gtk.FALSE, 0) vbox.add(hbox) hbox.show() check = gtk.CheckButton("Editable") hbox.pack_start(check, gtk.TRUE, gtk.TRUE, 0) check.connect("toggled", self.entry_toggle_editable, entry) check.set_active(gtk.TRUE) check.show() check = gtk.CheckButton("Visible") hbox.pack_start(check, gtk.TRUE, gtk.TRUE, 0) check.connect("toggled", self.entry_toggle_visibility, entry) check.set_active(gtk.TRUE) check.show() button = gtk.Button(stock=gtk.STOCK_CLOSE) button.connect_object("clicked", gtk.mainquit, window) vbox.pack_start(button, gtk.TRUE, gtk.TRUE, 0) button.set_flags(gtk.CAN_DEFAULT) button.grab_default() button.show() window.show() def main(): gtk.main() return 0 if __name__ == "__main__": EntryExample() main()