Ver Mensaje Individual
  #2 (permalink)  
Antiguo 16/10/2011, 16:29
Avatar de razpeitia
razpeitia
Moderador
 
Fecha de Ingreso: marzo-2005
Ubicación: Monterrey, México
Mensajes: 7.321
Antigüedad: 19 años, 2 meses
Puntos: 1360
Respuesta: Añadir botones dinamicamente. GTK

Código Python:
Ver original
  1. #!/usr/bin/env python
  2.  
  3. import pygtk
  4. pygtk.require('2.0')
  5. import gtk
  6.  
  7. class MyApp():
  8.    
  9.     def createButton(self, widget, data=None):
  10.         button = gtk.Button("Button %d" % self.counter)
  11.         button.connect("clicked", self.onClick, self.counter)
  12.         button.show()
  13.         self.Vbox.add(button)
  14.         self.buttons.append(button)
  15.         self.counter += 1
  16.    
  17.     def onClick(self, widget, data=None):
  18.         print "Click on button", data
  19.    
  20.     def __init__(self):
  21.         self.counter = 0
  22.         self.buttons = []
  23.        
  24.         self.window = gtk.Window()
  25.         self.Vbox = gtk.VBox()
  26.         self.button = gtk.Button("Make button")
  27.        
  28.         self.window.set_border_width(10)
  29.         self.Vbox.add(self.button)
  30.         self.window.add(self.Vbox)
  31.        
  32.         self.window.connect("destroy", gtk.main_quit)
  33.         self.button.connect("clicked", self.createButton, None)
  34.        
  35.         self.window.show_all()
  36.        
  37. if __name__ == "__main__":
  38.     app = MyApp()
  39.     gtk.main()
Aquí te dejo un código de ejemplo.