5_grid_layout.py 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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.grid = Gtk.Grid()
  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.grid.add(self.button)
  33. self.grid.attach(self.exit_button, 1, 0, 1, 1)
  34. self.grid.attach_next_to(Gtk.Label('No hacer nada'), self.button, Gtk.PositionType.BOTTOM, 2, 1)
  35. self.grid.attach(Gtk.Button('Correr'), 0, 2, 1, 1)
  36. self.add(self.grid)
  37. def button_clicked(self, widget):
  38. print('Hola')
  39. def exit(self, widget):
  40. print('Hasta otra. Gracias por usar el programa.')
  41. sys.exit(0)
  42. if __name__ == '__main__':
  43. win = Window()
  44. win.connect('delete-event', Gtk.main_quit)
  45. win.show_all()
  46. Gtk.main()