After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 685406 - Update python code from http://developer.gnome.org/gnome-devel-demos/unstable/entry.py.html.en
Update python code from http://developer.gnome.org/gnome-devel-demos/unstable...
Status: RESOLVED FIXED
Product: gnome-devel-docs
Classification: Applications
Component: platform-demos
unspecified
Other Linux
: Normal normal
: ---
Assigned To: gnome-devel-docs maintainers
gnome-devel-docs maintainers
Depends on:
Blocks: python3
 
 
Reported: 2012-10-03 15:54 UTC by Carlos Soriano
Modified: 2014-01-27 00:19 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Carlos Soriano 2012-10-03 15:54:57 UTC
from gi.repository import Gtk
import sys

class MyWindow(Gtk.ApplicationWindow):
    def __init__(self, app):
        Gtk.Window.__init__(self, title="What is your name?", application=app)
        self.set_default_size(300, 100)
        self.set_border_width(10)

        # a single line entry
        name_box = Gtk.Entry()
        # emits a signal when the Enter key is pressed, connected to the
        # callback function cb_activate
        name_box.connect("activate", self.cb_activate)

        # add the Gtk.Entry to the window
        self.add(name_box)

    # the content of the entry is used to write in the terminal
    def cb_activate(self, entry):
        # retrieve the content of the widget
        name = entry.get_text()
        # print it in a nice form in the terminal
        print("Hello " + name + "!")

class MyApplication(Gtk.Application):
    def __init__(self):
        Gtk.Application.__init__(self)

    def do_activate(self):
        win = MyWindow(self)
        win.show_all()

    def do_startup(self):
        Gtk.Application.do_startup(self)

app = MyApplication()
exit_status = app.run(sys.argv)
sys.exit(exit_status)
Comment 1 David King 2014-01-26 23:46:31 UTC
Indentation fixed in master as 60ac45d75933349a81afd4a853d206f1de201059. The Python 3 changes will have to wait until later.
Comment 2 Carlos Soriano 2014-01-27 00:19:17 UTC
Sure, np