python de Gtk+3 #8
次は、エントリーについて…
#!/usr/bin/env python # -*- coding:utf-8 -*- from gi.repository import Gtk class MainWindow(Gtk.Window): def __init__(self): Gtk.Window.__init__(self, title=u'Entry') vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=5) self.add(vbox) hbox = Gtk.Box(spacing=5) vbox.pack_start(hbox, True, True, 0) self.entry = Gtk.Entry() self.entry.set_text(u'Hello World') hbox.pack_start(self.entry, True, True, 0) self.button = Gtk.Button(u'OK') self.button.connect('clicked', self.on_button_clicked) hbox.pack_start(self.button, True, True, 0) self.label = Gtk.Label(self.entry.get_text()) vbox.pack_start(self.label, True, True, 0) self.connect('delete-event', Gtk.main_quit) self.show_all() def on_button_clicked(self, widget, event=None): self.label.set_text('%s' % (self.entry.get_text())) if __name__ == '__main__': MainWindow() Gtk.main()
これでOKボタンを押すことで、エントリーの文字を下のラベルに表示できます。