Foros del Web » Programando para Internet » Python »

Añadir botones dinamicamente. GTK

Estas en el tema de Añadir botones dinamicamente. GTK en el foro de Python en Foros del Web. Buenas hoy vengo con una incógnita, Es la siguiente: Como añadir botones dinamicamente con gtk. Ej: al dar click en un boton que cree otro. ...
  #1 (permalink)  
Antiguo 16/10/2011, 13:30
Avatar de Lautaro_eb  
Fecha de Ingreso: mayo-2010
Ubicación: Bariloche, Argentina
Mensajes: 284
Antigüedad: 13 años, 11 meses
Puntos: 24
Sonrisa Añadir botones dinamicamente. GTK

Buenas hoy vengo con una incógnita, Es la siguiente: Como añadir botones dinamicamente con gtk. Ej: al dar click en un boton que cree otro. Este es mi Code para que vean o si quieren usarlo para seguir el ejemplo.
Desde ya muchas gracias.
Código Python:
Ver original
  1. #! /usr/bin/env python
  2. # -*- coding: UTF-8 -*-
  3.  
  4. import pygtk
  5. pygtk.require("2.0")
  6. import gtk
  7. import gtk.glade
  8.  
  9. class test:
  10.     def __init__(self):
  11.         #Abriendo
  12.         self.wTree = gtk.glade.XML("linkiWork.glade")
  13.        
  14.         self.wTree.signal_autoconnect(self)
  15.        
  16.         self.window = self.wTree.get_widget("window1")
  17.        
  18.         self.window.show()
  19.     #Aca Estaba Provando pero no funciona.
  20.     def nuevo(self, *args):
  21.         boton = gtk.Button("Nuevo jeje");
  22.         boton.connect("clicked",self.nuevo)
  23.         self.wTree.get_widget("vbox1").add(boton)
  24.  
  25.        
  26.         print "Provando che ..."
  27.        
  28. if __name__ == "__main__":
  29.     test()
  30.     gtk.main()
__________________
Mi emprendimiento: Software BRC
Youtube: Tutoriales de programación y electrónica.
  #2 (permalink)  
Antiguo 16/10/2011, 16:29
Avatar de razpeitia
Moderador
 
Fecha de Ingreso: marzo-2005
Ubicación: Monterrey, México
Mensajes: 7.321
Antigüedad: 19 años, 1 mes
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.

Etiquetas: gtk, gtk+, graficos
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 01:22.