Blame platform-demos/C/samples/entry.py
|
Packit |
1470ea |
from gi.repository import Gtk
|
|
Packit |
1470ea |
import sys
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
class MyWindow(Gtk.ApplicationWindow):
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
def __init__(self, app):
|
|
Packit |
1470ea |
Gtk.Window.__init__(self, title="What is your name?", application=app)
|
|
Packit |
1470ea |
self.set_default_size(300, 100)
|
|
Packit |
1470ea |
self.set_border_width(10)
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
# a single line entry
|
|
Packit |
1470ea |
name_box = Gtk.Entry()
|
|
Packit |
1470ea |
# emits a signal when the Enter key is pressed, connected to the
|
|
Packit |
1470ea |
# callback function cb_activate
|
|
Packit |
1470ea |
name_box.connect("activate", self.cb_activate)
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
# add the Gtk.Entry to the window
|
|
Packit |
1470ea |
self.add(name_box)
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
# the content of the entry is used to write in the terminal
|
|
Packit |
1470ea |
def cb_activate(self, entry):
|
|
Packit |
1470ea |
# retrieve the content of the widget
|
|
Packit |
1470ea |
name = entry.get_text()
|
|
Packit |
1470ea |
# print it in a nice form in the terminal
|
|
Packit |
1470ea |
print("Hello " + name + "!")
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
class MyApplication(Gtk.Application):
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
def __init__(self):
|
|
Packit |
1470ea |
Gtk.Application.__init__(self)
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
def do_activate(self):
|
|
Packit |
1470ea |
win = MyWindow(self)
|
|
Packit |
1470ea |
win.show_all()
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
def do_startup(self):
|
|
Packit |
1470ea |
Gtk.Application.do_startup(self)
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
app = MyApplication()
|
|
Packit |
1470ea |
exit_status = app.run(sys.argv)
|
|
Packit |
1470ea |
sys.exit(exit_status)
|