4_box_layout.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. # Simple window - Just a simple window
  4. # Copyright (c) 2016 Jorge Maldonado Ventura
  5. #
  6. # This file is part of Simple window
  7. #
  8. # This program is free software: you can redistribute it and/or modify
  9. # it under the terms of the GNU General Public License as published by
  10. # the Free Software Foundation, either version 3 of the License, or
  11. # (at your option) any later version.
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU General Public License for more details.
  16. # You should have received a copy of the GNU General Public License
  17. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. import gi
  19. import sys
  20. gi.require_version('Gtk', '3.0')
  21. from gi.repository import Gtk
  22. class Window(Gtk.Window):
  23. def __init__(self):
  24. Gtk.Window.__init__(self, title='Saludar')
  25. self.set_default_size(400, 300)
  26. self.set_border_width(140)
  27. self.box = Gtk.HBox()
  28. self.button = Gtk.Button('Saludar')
  29. self.button.connect('clicked', self.button_clicked)
  30. self.exit_button = Gtk.Button('Salir')
  31. self.exit_button.connect('clicked', self.exit)
  32. self.box.add(self.button)
  33. self.box.add(self.exit_button)
  34. self.add(self.box)
  35. def button_clicked(self, widget):
  36. print('Hola')
  37. def exit(self, widget):
  38. print('Hasta otra. Gracias por usar el programa.')
  39. sys.exit(0)
  40. if __name__ == '__main__':
  41. win = Window()
  42. win.connect('delete-event', Gtk.main_quit)
  43. win.show_all()
  44. Gtk.main()