Foros del Web » Programando para Internet » Python »

Poner una Imagen de BackGround

Estas en el tema de Poner una Imagen de BackGround en el foro de Python en Foros del Web. Buenas. Tengo una ventana hecha en pygtk, a la misma le puse una imagen de background, debo agregar y contenedor de layout pues debo realizar ...
  #1 (permalink)  
Antiguo 03/01/2012, 17:50
 
Fecha de Ingreso: octubre-2011
Mensajes: 9
Antigüedad: 12 años, 6 meses
Puntos: 1
Poner una Imagen de BackGround

Buenas.

Tengo una ventana hecha en pygtk, a la misma le puse una imagen de background, debo agregar y contenedor de layout pues debo realizar drag and drop, pero cuando pongo en la ventana el layout la imagen que tenia de fondo en la ventana desaparece y no se como hacerla volver.

Según lo que vento leyendo, a nivel del layout no tengo forma de setearle una imagen de background.

Les agradezco si me tiran una linea de ayuda.
Saludos
  #2 (permalink)  
Antiguo 03/01/2012, 21:03
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: Poner una Imagen de BackGround

Algo de código de cortesía?
  #3 (permalink)  
Antiguo 04/01/2012, 05:57
 
Fecha de Ingreso: octubre-2011
Mensajes: 9
Antigüedad: 12 años, 6 meses
Puntos: 1
Respuesta: Poner una Imagen de BackGround

Disculpe el olvido, estoy siguiendo el ejemplo de layout.py además de una faq de gtk donde indican como se pone una imagen de background.

Cita:
#!/usr/bin/env python

import pygtk
pygtk.require('2.0')
import gtk, os
import random

iconsdir = './icons'
imagename = 'image.png'


class LayoutExample:
def WindowDeleteEvent(self, widget, event):
# return false so that window will be destroyed
return gtk.FALSE

def WindowDestroy(self, widget, *data):
# exit main loop
gtk.main_quit()

def ButtonClicked(self, button):
# move the button
self.layout.move(button, random.randint(0,500),
random.randint(0,500))

def __init__(self):
# create the top level window
window = gtk.Window(gtk.WINDOW_TOPLEVEL)
window.set_title("Layout Example")
window.set_default_size(300, 300)
window.connect("delete-event", self.WindowDeleteEvent)
window.connect("destroy", self.WindowDestroy)

path = os.path.join(iconsdir, imagename)
pixbuf = gtk.gdk.pixbuf_new_from_file(path)
pixmap, mask = pixbuf.render_pixmap_and_mask()
width, height = pixmap.get_size()
del pixbuf

window.shape_combine_mask(mask, 0, 0) # make it transparent, not necessary
window.window.set_back_pixmap(pixmap, gtk.FALSE)
del pixmap

window.invalidate_rect( rect, False )

# create the table and pack into the window
table = gtk.Table(2, 2, gtk.FALSE)
window.add(table)
# create the layout widget and pack into the table
self.layout = gtk.Layout(None, None)
self.layout.set_size(600, 600)
table.attach(self.layout, 0, 1, 0, 1, gtk.FILL|gtk.EXPAND,
gtk.FILL|gtk.EXPAND, 0, 0)
# create the scrollbars and pack into the table
vScrollbar = gtk.VScrollbar(None)
table.attach(vScrollbar, 1, 2, 0, 1, gtk.FILL|gtk.SHRINK,
gtk.FILL|gtk.SHRINK, 0, 0)
hScrollbar = gtk.HScrollbar(None)
table.attach(hScrollbar, 0, 1, 1, 2, gtk.FILL|gtk.SHRINK,
gtk.FILL|gtk.SHRINK, 0, 0)
# tell the scrollbars to use the layout widget's adjustments
vAdjust = self.layout.get_vadjustment()
vScrollbar.set_adjustment(vAdjust)
hAdjust = self.layout.get_hadjustment()
hScrollbar.set_adjustment(hAdjust)
# create 3 buttons and put them into the layout widget
button = gtk.Button("Press Me")
button.connect("clicked", self.ButtonClicked)
self.layout.put(button, 0, 0)
button = gtk.Button("Press Me")
button.connect("clicked", self.ButtonClicked)
self.layout.put(button, 100, 0)
button = gtk.Button("Press Me")
button.connect("clicked", self.ButtonClicked)
self.layout.put(button, 200, 0)
# show all the widgets
window.show_all()

def main():
# enter the main loop
gtk.main()
return 0

if __name__ == "__main__":
LayoutExample()
main()
Gracias por el tiempo dispensado
  #4 (permalink)  
Antiguo 22/01/2012, 17:31
 
Fecha de Ingreso: enero-2012
Mensajes: 1
Antigüedad: 12 años, 2 meses
Puntos: 0
Respuesta: Poner una Imagen de BackGround

Al parecer tu imagen desaparece por que queda detrás del layout, he buscado tambien como ponerla en el layout pero hasta el momento no he tenido exito, lo que se he podido hacer es ponerla en un eventbox.
  #5 (permalink)  
Antiguo 23/01/2012, 12:59
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: Poner una Imagen de BackGround

Tu código no me corre en ubuntu 11.10.

Bueno al menos dejo tu mismo código pero indentado.

Código Python:
Ver original
  1. #!/usr/bin/env python
  2.  
  3. import pygtk
  4. pygtk.require('2.0')
  5. import gtk, os
  6. import random
  7.  
  8. iconsdir = './icons'
  9. imagename = 'image.png'
  10.  
  11.  
  12. class LayoutExample:
  13.     def WindowDeleteEvent(self, widget, event):
  14.         # return false so that window will be destroyed
  15.         return gtk.FALSE
  16.    
  17.     def WindowDestroy(self, widget, *data):
  18.         # exit main loop
  19.         gtk.main_quit()
  20.    
  21.     def ButtonClicked(self, button):
  22.         # move the button
  23.         self.layout.move(button, random.randint(0,500),
  24.         random.randint(0,500))
  25.    
  26.     def __init__(self):
  27.         # create the top level window
  28.         window = gtk.Window(gtk.WINDOW_TOPLEVEL)
  29.         window.set_title("Layout Example")
  30.         window.set_default_size(300, 300)
  31.         window.connect("delete-event", self.WindowDeleteEvent)
  32.         window.connect("destroy", self.WindowDestroy)
  33.        
  34.         path = os.path.join(iconsdir, imagename)
  35.         pixbuf = gtk.gdk.pixbuf_new_from_file(path)
  36.         pixmap, mask = pixbuf.render_pixmap_and_mask()
  37.         width, height = pixmap.get_size()
  38.         del pixbuf
  39.        
  40.         window.shape_combine_mask(mask, 0, 0) # make it transparent, not necessary
  41.         window.window.set_back_pixmap(pixmap, gtk.FALSE)
  42.         del pixmap
  43.        
  44.         window.invalidate_rect( rect, False )
  45.        
  46.         # create the table and pack into the window
  47.         table = gtk.Table(2, 2, gtk.FALSE)
  48.         window.add(table)
  49.         # create the layout widget and pack into the table
  50.         self.layout = gtk.Layout(None, None)
  51.         self.layout.set_size(600, 600)
  52.         table.attach(self.layout, 0, 1, 0, 1, gtk.FILL|gtk.EXPAND,
  53.         gtk.FILL|gtk.EXPAND, 0, 0)
  54.         # create the scrollbars and pack into the table
  55.         vScrollbar = gtk.VScrollbar(None)
  56.         table.attach(vScrollbar, 1, 2, 0, 1, gtk.FILL|gtk.SHRINK,
  57.         gtk.FILL|gtk.SHRINK, 0, 0)
  58.         hScrollbar = gtk.HScrollbar(None)
  59.         table.attach(hScrollbar, 0, 1, 1, 2, gtk.FILL|gtk.SHRINK,
  60.         gtk.FILL|gtk.SHRINK, 0, 0)
  61.         # tell the scrollbars to use the layout widget's adjustments
  62.         vAdjust = self.layout.get_vadjustment()
  63.         vScrollbar.set_adjustment(vAdjust)
  64.         hAdjust = self.layout.get_hadjustment()
  65.         hScrollbar.set_adjustment(hAdjust)
  66.         # create 3 buttons and put them into the layout widget
  67.         button = gtk.Button("Press Me")
  68.         button.connect("clicked", self.ButtonClicked)
  69.         self.layout.put(button, 0, 0)
  70.         button = gtk.Button("Press Me")
  71.         button.connect("clicked", self.ButtonClicked)
  72.         self.layout.put(button, 100, 0)
  73.         button = gtk.Button("Press Me")
  74.         button.connect("clicked", self.ButtonClicked)
  75.         self.layout.put(button, 200, 0)
  76.         # show all the widgets
  77.         window.show_all()
  78.  
  79. def main():
  80.     # enter the main loop
  81.     gtk.main()
  82.     return 0
  83.  
  84. if __name__ == "__main__":
  85.     LayoutExample()
  86.     main()

Etiquetas: ventanas, formulario, fondo
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 22:12.