Ver Mensaje Individual
  #5 (permalink)  
Antiguo 23/01/2012, 12:59
Avatar de razpeitia
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()