12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- # Simple window - Just a simple window
- # Copyright (c) 2016 Jorge Maldonado Ventura
- #
- # This file is part of Simple window
- #
- # This program is free software: you can redistribute it and/or modify
- # it under the terms of the GNU General Public License as published by
- # the Free Software Foundation, either version 3 of the License, or
- # (at your option) any later version.
- # This program is distributed in the hope that it will be useful,
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- # GNU General Public License for more details.
- # You should have received a copy of the GNU General Public License
- # along with this program. If not, see <http://www.gnu.org/licenses/>.
- import gi
- import sys
- gi.require_version('Gtk', '3.0')
- from gi.repository import Gtk
- class Window(Gtk.Window):
- def __init__(self):
- Gtk.Window.__init__(self, title='Saludar')
- self.set_default_size(400, 300)
- self.set_border_width(140)
- self.set_position(Gtk.WindowPosition.CENTER)
- self.grid = Gtk.Grid()
- self.grid.set_column_homogeneous(True)
- self.user_name = Gtk.Entry()
- self.user_name.set_text('Introduce aquí tu nombre de usuario')
- self.passwd = Gtk.Entry()
- self.passwd.set_visibility(False)
- self.login_button = Gtk.Button('Iniciar sesión')
- self.login_button.connect('clicked', self.login)
- self.exit_button = Gtk.Button('Salir')
- self.exit_button.connect('clicked', self.exit)
- self.grid.attach(self.user_name, 0, 0, 2, 1)
- self.grid.attach(self.passwd, 0, 1, 2, 1)
- self.grid.attach(self.exit_button, 0, 2, 1, 1)
- self.grid.attach(self.login_button, 1, 2, 1, 1)
- self.add(self.grid)
- def login(self, widget):
- if self.passwd.get_text() == 'secreta':
- print('Bienvenido a tu cuenta, ' + self.user_name.get_text() + '.')
- else:
- print('Lo siento, la contraseña introducida es incorrecta.')
- sys.exit(1)
- def exit(self, widget):
- print('Hasta otra. Gracias por usar el programa.')
- sys.exit(0)
- if __name__ == '__main__':
- win = Window()
- win.connect('delete-event', Gtk.main_quit)
- win.show_all()
- Gtk.main()
|